﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using Assist;
using Autodesk.Revit.DB;
using Autodesk.Revit.DB.Plumbing;
using Autodesk.Revit.UI.Selection;
using YArchitech.Controls;
using YArchitech.Revit;

namespace YArchitech.HVAC
{
	public class RadiatorConnHelper
	{
		public RadiatorConnHelper(Autodesk.Revit.DB.Document doc, Selection sel)
		{
			this.doc = doc;
			this.sel = sel;
		}

		public bool SelectElementSet()
		{
			string text = "请选择需连接的散热器及其相应的水管……";
			List<Element> list = null;
			for (;;)
			{
				list = new List<Element>();
				if (this.Sel.GetElementIds().Count > 0)
				{
					foreach (ElementId elementId in this.Sel.GetElementIds())
					{
						list.Add(this.Doc.GetElementById(elementId));
					}
					this.Message = this.ValidatingElements(list);
					if (string.IsNullOrEmpty(this.Message))
					{
						break;
					}
					YJKMessageBox.Information(this.Message);
					RevitVersionFuncs.ClearSelection(this.Sel);
				}
				else
				{
					HYRadiatorAndPipeFilter hyradiatorAndPipeFilter = new HYRadiatorAndPipeFilter();
					list = this.Sel.PickElementsByRectangle(hyradiatorAndPipeFilter, text).ToList<Element>();
					this.Message = this.ValidatingElements(list);
					if (string.IsNullOrEmpty(this.Message))
					{
						goto IL_F0;
					}
					YJKMessageBox.Information(this.Message);
					RevitVersionFuncs.ClearSelection(this.Sel);
				}
			}
			bool result = true;
			goto IL_F2;
			IL_F0:
			result = true;
			IL_F2:
			this.GetConningPipes();
			return result;
		}

		private void GetConningPipes()
		{
			if (this.ConnStyle == 1 && this.ListPipe.Count > 1)
			{
				this.supplyPipe = null;
				this.returnPipe = null;
				foreach (Pipe pipe in this.ListPipe)
				{
					if (this.JudgePipingSystem(pipe) == 1)
					{
						this.supplyPipe = pipe;
					}
					if (this.JudgePipingSystem(pipe) == 2)
					{
						this.returnPipe = pipe;
					}
				}
				if (this.supplyPipe != null)
				{
					this.ListPipe.Remove(this.supplyPipe);
				}
				if (this.returnPipe != null)
				{
					this.ListPipe.Remove(this.returnPipe);
				}
				if (this.supplyPipe == null && this.ListPipe.Count > 0)
				{
					this.supplyPipe = this.ListPipe[0];
					this.ListPipe.Remove(this.supplyPipe);
				}
				if (this.returnPipe == null && this.ListPipe.Count > 0)
				{
					this.returnPipe = this.ListPipe[0];
				}
				if (this.returnPipe != null && this.supplyPipe == null)
				{
					this.supplyPipe = this.returnPipe;
					return;
				}
			}
			else if (this.ListPipe.Count > 0)
			{
				this.supplyPipe = null;
				this.returnPipe = null;
				foreach (Pipe pipe2 in this.ListPipe)
				{
					if (this.JudgePipingSystem(pipe2) == 1)
					{
						this.supplyPipe = pipe2;
					}
				}
				if (this.supplyPipe == null)
				{
					this.supplyPipe = this.ListPipe[0];
				}
			}
		}

		private int JudgePipingSystem(Pipe pipe)
		{
			int result = 0;
			PipeSystemType pipeSystemType = new YJKPiping<Pipe>(pipe).GetConnectorPipingSystemType().pipeSystemType;
            if ((int)pipeSystemType == 7)
			{
				result = 1;
			}
            else if ((int)pipeSystemType == 8)
			{
				result = 2;
			}
			return result;
		}

		private Connector GetConnector(FamilyInstance fiRadiator, int styleNum)
		{
			Connector result = null;
			foreach (Connector connector in YJKRevitTools.GetElementConnector(fiRadiator, (Autodesk.Revit.DB.Domain)3))
			{
				if (styleNum == 1 && (int)connector.PipeSystemType == 7)
				{
					result = connector;
				}
				if (styleNum == 2 && (int)connector.PipeSystemType == 8)
				{
					result = connector;
				}
			}
			return result;
		}

		private void GetConnecctor(FamilyInstance fiRadiator, ref Connector inConn, ref Connector outConn)
		{
			List<Connector> elementConnector = YJKRevitTools.GetElementConnector(fiRadiator, (Autodesk.Revit.DB.Domain)3);
			if (elementConnector.Count < 2)
			{
				return;
			}
			Parameter parameter = fiRadiator.GetParameter("HYRadiatorType");
			if (parameter == null)
			{
				return;
			}
			string text = parameter.AsString();
			uint num = YArchitech.Revit.PrivateImplementationDetails.ComputeStringHash(text);
			if (num <= 2279835011u)
			{
				if (num <= 518729469u)
				{
					if (num != 401286136u)
					{
						if (num != 501951850u)
						{
							if (num != 518729469u)
							{
								goto IL_26C;
							}
							if (!(text == "13"))
							{
								goto IL_26C;
							}
						}
						else
						{
							if (!(text == "12"))
							{
								goto IL_26C;
							}
							goto IL_200;
						}
					}
					else if (!(text == "14"))
					{
						goto IL_26C;
					}
				}
				else if (num != 2247118416u)
				{
					if (num != 2263057392u)
					{
						if (num != 2279835011u)
						{
							goto IL_26C;
						}
						if (!(text == "42"))
						{
							goto IL_26C;
						}
						goto IL_1EB;
					}
					else
					{
						if (!(text == "43"))
						{
							goto IL_26C;
						}
						goto IL_236;
					}
				}
				else
				{
					if (!(text == "32"))
					{
						goto IL_26C;
					}
					goto IL_1EB;
				}
			}
			else if (num <= 2314375987u)
			{
				if (num != 2296612630u)
				{
					if (num != 2297451273u)
					{
						if (num != 2314375987u)
						{
							goto IL_26C;
						}
						if (!(text == "24"))
						{
							goto IL_26C;
						}
					}
					else
					{
						if (!(text == "31"))
						{
							goto IL_26C;
						}
						goto IL_1EB;
					}
				}
				else
				{
					if (!(text == "41"))
					{
						goto IL_26C;
					}
					goto IL_1EB;
				}
			}
			else if (num != 2347784130u)
			{
				if (num != 2364708844u)
				{
					if (num != 2398264082u)
					{
						goto IL_26C;
					}
					if (!(text == "23"))
					{
						goto IL_26C;
					}
				}
				else
				{
					if (!(text == "21"))
					{
						goto IL_26C;
					}
					goto IL_236;
				}
			}
			else
			{
				if (!(text == "34"))
				{
					goto IL_26C;
				}
				goto IL_200;
			}
			inConn = this.GetConnector(elementConnector, 0);
			outConn = this.GetConnector(elementConnector, 1);
			return;
			IL_1EB:
			inConn = this.GetConnector(elementConnector, 1);
			outConn = this.GetConnector(elementConnector, 0);
			return;
			IL_200:
			parameter = fiRadiator.GetParameter("HYRadiatorVector");
			if (parameter == null)
			{
				return;
			}
			text = parameter.AsString();
			XYZ pointValue = this.GetPointValue(text);
			inConn = this.GetConnector(elementConnector, pointValue, 0);
			outConn = this.GetConnector(elementConnector, pointValue, 1);
			return;
			IL_236:
			parameter = fiRadiator.GetParameter("HYRadiatorVector");
			if (parameter == null)
			{
				return;
			}
			text = parameter.AsString();
			pointValue = this.GetPointValue(text);
			inConn = this.GetConnector(elementConnector, pointValue, 1);
			outConn = this.GetConnector(elementConnector, pointValue, 0);
			return;
			IL_26C:
			inConn = elementConnector[0];
			outConn = elementConnector[1];
		}

		private XYZ GetPointValue(string typeValue)
		{
			string[] array = typeValue.Substring(1, typeValue.Length - 2).Split(new char[]
			{
				','
			});
			return new XYZ(Convert.ToDouble(array[0]), Convert.ToDouble(array[1]), Convert.ToDouble(array[2]));
		}

		private Connector GetConnector(List<Connector> listConn, int pntNum = 0)
		{
			Connector result = null;
			XYZ origin = listConn[0].Origin;
			XYZ origin2 = listConn[1].Origin;
			if (pntNum == 0)
			{
				if (origin.Z > origin2.Z)
				{
					result = listConn[0];
				}
				else
				{
					result = listConn[1];
				}
			}
			if (pntNum == 1)
			{
				if (origin.Z > origin2.Z)
				{
					result = listConn[1];
				}
				else
				{
					result = listConn[0];
				}
			}
			return result;
		}

		private Connector GetConnector(List<Connector> listConn, XYZ baseVector, int pntNum = 0)
		{
			Connector result = null;
			XYZ origin = listConn[0].Origin;
			XYZ xyz = listConn[1].Origin.Subtract(origin).Normalize();
			if (pntNum == 0)
			{
				if (baseVector.IsAlmostEqualTo(xyz, 0.0001))
				{
					result = listConn[0];
				}
				else
				{
					result = listConn[1];
				}
			}
			if (pntNum == 1)
			{
				if (baseVector.IsAlmostEqualTo(xyz, 0.0001))
				{
					result = listConn[1];
				}
				else
				{
					result = listConn[0];
				}
			}
			return result;
		}

		public bool ConnectRadiatorSet(XYZ basePnt, ref int notConnNum)
		{
			bool result = true;
			if (this.ConnStyle == 1)
			{
				if (this.SupplyPipe == null || this.ReturnPipe == null)
				{
					result = false;
					this.message = "连接管道不能为空！";
					return result;
				}
				if (YJKRevitTools.isRiserPipe(this.SupplyPipe) && YJKRevitTools.isRiserPipe(this.ReturnPipe))
				{
					result = this.ConnRiserRadiator();
				}
				else if (!YJKRevitTools.isRiserPipe(this.SupplyPipe) && !YJKRevitTools.isRiserPipe(this.ReturnPipe))
				{
					result = this.ConnRadiators(basePnt, ref notConnNum);
				}
				else
				{
					result = false;
					this.message = "选择的管道应同为立管或水平管！";
				}
			}
			else
			{
				if (this.SupplyPipe == null)
				{
					result = false;
					this.message = "连接管道不能为空！";
					return result;
				}
				if (YJKRevitTools.isRiserPipe(this.SupplyPipe))
				{
					result = this.ConnRiserRadiator();
				}
				else if (!YJKRevitTools.isRiserPipe(this.SupplyPipe))
				{
					result = this.ConnRadiators(basePnt, ref notConnNum);
				}
			}
			return result;
		}

		public bool ConnRiserRadiator()
		{
			bool result = true;
			RadiatorConnParam radiatorConnParam = this.InitialRadiatorParam(this.ListRadiator[0]);
			if (radiatorConnParam.InConnector == null || radiatorConnParam.OutConnector == null)
			{
				throw new Exception("未能找到连接用的进口或出口连接件，请检查散热器族，\n或者用布置散热器重新布置族！");
			}
			RadiatorConnParam radiatorConnParam2 = this.CreatLeadPipe(radiatorConnParam);
			if (radiatorConnParam2 == null)
			{
				return false;
			}
			if (this.ConnStyle == 1)
			{
				result = this.ConnDoublePipes(radiatorConnParam2);
			}
			if (this.ConnStyle == 2)
			{
				result = this.ConnDownPipes(radiatorConnParam2);
			}
			if (this.ConnStyle == 3)
			{
				result = this.ConnCrossPipes(radiatorConnParam2);
			}
			return result;
		}

		public bool ConnRadiators(XYZ basePnt, ref int notConnNum)
		{
			bool result = true;
			int num = 0;
			List<RadiatorConnParam> list = this.InitialRadiatorParam(this.ListRadiator);
			List<RadiatorConnParam> list2 = new List<RadiatorConnParam>();
			foreach (RadiatorConnParam radiatorConnParam in list)
			{
				if (radiatorConnParam.InConnector != null && radiatorConnParam.OutConnector != null)
				{
					list2.Add(radiatorConnParam);
				}
			}
			if (list2.Count < 1)
			{
				throw new Exception("未能找到连接用的进口或出口连接件，请检查散热器族，\n或者用布置散热器重新布置族！");
			}
			List<RadiatorConnParam> list3 = this.CreatLeadPipe(list2);
			if (list3 == null || list3.Count < 1)
			{
				return false;
			}
			List<RadiatorConnParam> list4 = this.OrderByRadiatorSingle(list3, ref basePnt);
			if (list4 == null || list4.Count < 1)
			{
				result = false;
				return result;
			}
			if (this.ConnStyle == 1)
			{
				result = this.ConnDoublePipes(list4, basePnt, ref num);
			}
			if (this.ConnStyle == 2)
			{
				result = this.ConnDownPipes(list4, basePnt);
			}
			if (this.ConnStyle == 3)
			{
				result = this.ConnCrossPipes(list4, basePnt);
			}
			int num2 = list.Count - list2.Count;
			if (num2 > 0)
			{
				result = false;
				YJKMessageBox.Information("选择连接的散热器中有" + num2 + "个散热器族，\n由于族的问题找不到相应的连接口，\n不能进行连接，请检查！");
			}
			notConnNum = list.Count - num;
			if (this.ConnStyle != 1)
			{
				notConnNum = 0;
			}
			return result;
		}

		public XYZ GetBasePoint()
		{
			XYZ result = null;
			if (this.SupplyPipe == null)
			{
				return result;
			}
			YJKPiping<Pipe> hypiping = new YJKPiping<Pipe>(this.SupplyPipe);
			XYZ origin = hypiping.StartConnector.Connector.Origin;
			XYZ origin2 = hypiping.EndConnector.Connector.Origin;
			XYZ loctaionPoint = YJKRevitTools.GetLoctaionPoint(this.ListRadiator[0]);
			return (origin.DistanceTo(loctaionPoint) > origin2.DistanceTo(loctaionPoint)) ? origin2 : origin;
		}

		private bool CheckPipeEquipmentRelation(Connector conn, Pipe pipe)
		{
			XYZ origin = conn.Origin;
			XYZ end = origin.Add(conn.CoordinateSystem.BasisZ);
			YJKLine hyline = new YJKLine(origin, end);
			YJKPiping<Pipe> hypiping = new YJKPiping<Pipe>(pipe);
			YJKLine hyline2 = new YJKLine(hypiping.StartConnector.Origin, hypiping.EndConnector.Origin);
			return hyline2.IsParallel(hyline.Line) || hyline2.IsVertical(hyline.Line);
		}

		private bool ConnDoublePipes(List<RadiatorConnParam> radiatorSet, XYZ basePnt, ref int connNum)
		{
			bool result = true;
			string empty = string.Empty;
			try
			{
				Pipe pipe = this.SupplyPipe;
				Pipe pipe2 = this.ReturnPipe;
				foreach (RadiatorConnParam radiatorConnParam in radiatorSet)
				{
					if ((this.CheckPipeEquipmentRelation(radiatorConnParam.InConnector, pipe) || this.CheckPipeEquipmentRelation(radiatorConnParam.OutConnector, pipe2)) && (!this.IsPerpendicularVector(radiatorConnParam.InConnector, pipe) || !this.IsPerpendicularVector(radiatorConnParam.OutConnector, pipe2) || (this.CheckConnVectorSame(radiatorConnParam.InConnector, pipe) && this.CheckConnVectorSame(radiatorConnParam.OutConnector, pipe2))))
					{
						SubTransaction subTransaction = new SubTransaction(pipe.Document);
						subTransaction.Start();
						RadiatorConnHelper.DoubleConnPipesType doubleConnPipesType = this.DistinguishConnStyle(radiatorConnParam, pipe, pipe2);
						IList<Pipe> list = new List<Pipe>();
						IList<Pipe> list2 = new List<Pipe>();
						this.riserPipe = new List<Pipe>();
						switch (doubleConnPipesType)
						{
						case RadiatorConnHelper.DoubleConnPipesType.HPipeNormal:
							list = this.ConnPipe(radiatorConnParam, pipe, 2);
							if (string.IsNullOrEmpty(this.Message))
							{
								list2 = this.ConnPipe(radiatorConnParam, pipe2, 1);
								if (string.IsNullOrEmpty(this.Message))
								{
									pipe = this.GetFarPipeToPoint(list, basePnt);
									pipe2 = this.GetFarPipeToPoint(list2, basePnt);
									this.Doc.Regenerate();
								}
							}
							break;
						case RadiatorConnHelper.DoubleConnPipesType.HPipeOverIn1:
							list = this.ConnPipeOver1(radiatorConnParam, pipe, 2, pipe2);
							if (string.IsNullOrEmpty(this.Message))
							{
								list2 = this.ConnPipe(radiatorConnParam, pipe2, 1);
								if (string.IsNullOrEmpty(this.Message))
								{
									pipe = this.GetFarPipeToPoint(list, basePnt);
									pipe2 = this.GetFarPipeToPoint(list2, basePnt);
									this.Doc.Regenerate();
								}
							}
							break;
						case RadiatorConnHelper.DoubleConnPipesType.HPipeOverIn2:
							list = this.ConnPipeOver2(radiatorConnParam, pipe, 2, pipe2);
							if (string.IsNullOrEmpty(this.Message))
							{
								list2 = this.ConnPipe(radiatorConnParam, pipe2, 1);
								if (string.IsNullOrEmpty(this.Message))
								{
									pipe = this.GetFarPipeToPoint(list, basePnt);
									pipe2 = this.GetFarPipeToPoint(list2, basePnt);
									this.Doc.Regenerate();
								}
							}
							break;
						case RadiatorConnHelper.DoubleConnPipesType.HPipeOverOut1:
							list2 = this.ConnPipeOver1(radiatorConnParam, pipe2, 1, pipe);
							if (string.IsNullOrEmpty(this.Message))
							{
								list = this.ConnPipe(radiatorConnParam, pipe, 2);
								if (string.IsNullOrEmpty(this.Message))
								{
									pipe2 = this.GetFarPipeToPoint(list2, basePnt);
									pipe = this.GetFarPipeToPoint(list, basePnt);
									this.Doc.Regenerate();
								}
							}
							break;
						case RadiatorConnHelper.DoubleConnPipesType.HPipeOverOut2:
							list2 = this.ConnPipeOver2(radiatorConnParam, pipe2, 1, pipe);
							if (string.IsNullOrEmpty(this.Message))
							{
								list = this.ConnPipe(radiatorConnParam, pipe, 2);
								if (string.IsNullOrEmpty(this.Message))
								{
									pipe2 = this.GetFarPipeToPoint(list2, basePnt);
									pipe = this.GetFarPipeToPoint(list, basePnt);
									this.Doc.Regenerate();
								}
							}
							break;
						case RadiatorConnHelper.DoubleConnPipesType.HPipeDoubleElbowIn:
							list = this.ConnPipeDoubleElbow(radiatorConnParam, pipe, 2, pipe2);
							if (string.IsNullOrEmpty(this.Message))
							{
								list2 = this.ConnPipe(radiatorConnParam, pipe2, 1);
								if (string.IsNullOrEmpty(this.Message))
								{
									pipe = this.GetFarPipeToPoint(list, basePnt);
									pipe2 = this.GetFarPipeToPoint(list2, basePnt);
									this.Doc.Regenerate();
								}
							}
							break;
						case RadiatorConnHelper.DoubleConnPipesType.HPipeDoubleElbowOut:
							list2 = this.ConnPipeDoubleElbow(radiatorConnParam, pipe2, 1, pipe);
							if (string.IsNullOrEmpty(this.Message))
							{
								list = this.ConnPipe(radiatorConnParam, pipe, 2);
								if (string.IsNullOrEmpty(this.Message))
								{
									pipe2 = this.GetFarPipeToPoint(list2, basePnt);
									pipe = this.GetFarPipeToPoint(list, basePnt);
									this.Doc.Regenerate();
								}
							}
							break;
						case RadiatorConnHelper.DoubleConnPipesType.HPipeDoubleElbow:
							list = this.ConnPipeDoubleElbow(radiatorConnParam, pipe, 2, pipe2);
							if (string.IsNullOrEmpty(this.Message))
							{
								Pipe farPipeToPoint = this.GetFarPipeToPoint(list, basePnt);
								list2 = this.ConnPipeDoubleElbow(radiatorConnParam, pipe2, 1, farPipeToPoint);
								if (string.IsNullOrEmpty(this.Message))
								{
									pipe = farPipeToPoint;
									pipe2 = this.GetFarPipeToPoint(list2, basePnt);
									this.Doc.Regenerate();
								}
							}
							break;
						case RadiatorConnHelper.DoubleConnPipesType.HPipeDoubleElbowInAndOverOut:
							list = this.ConnPipeDoubleElbow(radiatorConnParam, pipe, 2, pipe2);
							if (string.IsNullOrEmpty(this.Message))
							{
								Pipe farPipeToPoint2 = this.GetFarPipeToPoint(list, basePnt);
								list2 = this.ConnPipeOver2(radiatorConnParam, pipe2, 1, farPipeToPoint2);
								if (string.IsNullOrEmpty(this.Message))
								{
									pipe = farPipeToPoint2;
									pipe2 = this.GetFarPipeToPoint(list2, basePnt);
									this.Doc.Regenerate();
								}
							}
							break;
						case RadiatorConnHelper.DoubleConnPipesType.HPipeDoubleElbowOutAndOverIn:
							list2 = this.ConnPipeDoubleElbow(radiatorConnParam, pipe2, 1, pipe);
							if (string.IsNullOrEmpty(this.Message))
							{
								Pipe farPipeToPoint3 = this.GetFarPipeToPoint(list2, basePnt);
								list = this.ConnPipeOver2(radiatorConnParam, pipe, 2, farPipeToPoint3);
								if (string.IsNullOrEmpty(this.Message))
								{
									pipe2 = farPipeToPoint3;
									pipe = this.GetFarPipeToPoint(list, basePnt);
									this.Doc.Regenerate();
								}
							}
							break;
						case RadiatorConnHelper.DoubleConnPipesType.HPipeSingleElbowIn:
							list2 = this.ConnPipe(radiatorConnParam, pipe2, 1);
							if (string.IsNullOrEmpty(this.Message))
							{
								Pipe farPipeToPoint4 = this.GetFarPipeToPoint(list2, basePnt);
								list = this.ConnPipeSingleElbow(radiatorConnParam, pipe, 2, farPipeToPoint4);
								if (string.IsNullOrEmpty(this.Message))
								{
									pipe2 = farPipeToPoint4;
									pipe = this.GetFarPipeToPoint(list, basePnt);
									this.Doc.Regenerate();
								}
							}
							break;
						case RadiatorConnHelper.DoubleConnPipesType.HPipeSingleElbowOut:
							list = this.ConnPipe(radiatorConnParam, pipe, 2);
							if (string.IsNullOrEmpty(this.Message))
							{
								Pipe farPipeToPoint5 = this.GetFarPipeToPoint(list, basePnt);
								list2 = this.ConnPipeSingleElbow(radiatorConnParam, pipe2, 1, farPipeToPoint5);
								if (string.IsNullOrEmpty(this.Message))
								{
									pipe = farPipeToPoint5;
									pipe2 = this.GetFarPipeToPoint(list2, basePnt);
									this.Doc.Regenerate();
								}
							}
							break;
						case RadiatorConnHelper.DoubleConnPipesType.HPipeSingleElbowInAndOverOut:
							list = this.ConnPipeSingleElbow(radiatorConnParam, pipe, 2, pipe2);
							if (string.IsNullOrEmpty(this.Message))
							{
								Pipe farPipeToPoint6 = this.GetFarPipeToPoint(list, basePnt);
								list2 = this.ConnPipeOver2(radiatorConnParam, pipe2, 1, farPipeToPoint6);
								if (string.IsNullOrEmpty(this.Message))
								{
									pipe = farPipeToPoint6;
									pipe2 = this.GetFarPipeToPoint(list2, basePnt);
									this.Doc.Regenerate();
								}
							}
							break;
						case RadiatorConnHelper.DoubleConnPipesType.HPipeSingleElbowOutAndOverIn:
							list2 = this.ConnPipeSingleElbow(radiatorConnParam, pipe2, 1, pipe);
							if (string.IsNullOrEmpty(this.Message))
							{
								Pipe farPipeToPoint7 = this.GetFarPipeToPoint(list2, basePnt);
								list = this.ConnPipeOver2(radiatorConnParam, pipe, 2, farPipeToPoint7);
								if (string.IsNullOrEmpty(this.Message))
								{
									pipe2 = farPipeToPoint7;
									pipe = this.GetFarPipeToPoint(list, basePnt);
									this.Doc.Regenerate();
								}
							}
							break;
						case RadiatorConnHelper.DoubleConnPipesType.HPipeSingleElbow:
							list = this.ConnPipeSingleElbow(radiatorConnParam, pipe, 2, pipe2);
							if (string.IsNullOrEmpty(this.Message))
							{
								Pipe farPipeToPoint8 = this.GetFarPipeToPoint(list, basePnt);
								list2 = this.ConnPipeSingleElbow(radiatorConnParam, pipe2, 1, farPipeToPoint8);
								if (string.IsNullOrEmpty(this.Message))
								{
									pipe = farPipeToPoint8;
									pipe2 = this.GetFarPipeToPoint(list2, basePnt);
									this.Doc.Regenerate();
								}
							}
							break;
						case RadiatorConnHelper.DoubleConnPipesType.Invalid:
							this.Message = "Invalid";
							break;
						}
						this.BranchPipeConn(radiatorConnParam);
						if (string.IsNullOrEmpty(this.Message))
						{
							subTransaction.Commit();
							connNum++;
						}
						else
						{
							subTransaction.RollBack();
						}
					}
				}
			}
			catch (Exception ex)
			{
				result = false;
				this.Message = ex.Message;
			}
			return result;
		}

		private bool BranchPipeConn(RadiatorConnParam connParam)
		{
			bool result = true;
			foreach (Pipe pipe in this.riserPipe)
			{
				HYPipeConnect hypipeConnect = new HYPipeConnect();
				List<ElementId> elementByCollision = hypipeConnect.GetElementByCollision(pipe, (Autodesk.Revit.DB.BuiltInCategory)(-2008044), this.Doc);
				string text = "";
				List<Pipe> list = new List<Pipe>();
				if (connParam.InPipe.IsValidObject && elementByCollision.Contains(connParam.InPipe.Id))
				{
					result = hypipeConnect.NewUnionFittings(pipe, connParam.InPipe, this.Doc, -connParam.FacingOrientation, ref text, ref list);
					break;
				}
				if (connParam.OutPipe.IsValidObject && elementByCollision.Contains(connParam.OutPipe.Id))
				{
					result = hypipeConnect.NewUnionFittings(pipe, connParam.OutPipe, this.Doc, -connParam.FacingOrientation, ref text, ref list);
					break;
				}
			}
			this.riserPipe = new List<Pipe>();
			return result;
		}

		private bool IsPerpendicularVector(Connector connector, Pipe pipe)
		{
			XYZ origin = connector.Origin;
			XYZ end = origin.Add(connector.CoordinateSystem.BasisZ);
			YJKLine hyline = new YJKLine(origin, end);
			YJKPiping<Pipe> hypiping = new YJKPiping<Pipe>(pipe);
			return new YJKLine(hypiping.StartConnector.Origin, hypiping.EndConnector.Origin).IsVertical(hyline.Line);
		}

		private bool CheckConnVectorSame(Connector connector, Pipe pipe)
		{
			XYZ xyz = connector.CoordinateSystem.BasisZ.Normalize();
			YJKPiping<Pipe> hypiping = new YJKPiping<Pipe>(pipe);
			YJKLine hyline = new YJKLine(hypiping.StartConnector.Origin, hypiping.EndConnector.Origin);
			hyline.MakeUnBound();
			XYZ project = hyline.GetProject(connector.Origin);
			return new XYZ(project.X, project.Y, connector.Origin.Z).Subtract(connector.Origin).Normalize().IsAlmostEqualTo(xyz);
		}

		private RadiatorConnHelper.DoubleConnPipesType DistinguishConnStyle(RadiatorConnParam connParam, Pipe supplyPipe, Pipe returnPipe)
		{
			RadiatorConnHelper.DoubleConnPipesType result = RadiatorConnHelper.DoubleConnPipesType.Invalid;
			YJKPiping<Pipe> hypiping = new YJKPiping<Pipe>(supplyPipe);
			YJKPiping<Pipe> hypiping2 = new YJKPiping<Pipe>(returnPipe);
			FamilyInstance familyInstance = this.doc.GetElementById(new ElementId(connParam.ElementId)) as FamilyInstance;
			XYZ facingOrientation = familyInstance.FacingOrientation;
			XYZ handOrientation = familyInstance.HandOrientation;
			hypiping.GetOuterDiameter();
			hypiping2.GetOuterDiameter();
			if (!YJKRevitTools.isRiserPipe(supplyPipe) || !YJKRevitTools.isRiserPipe(returnPipe))
			{
				if (!YJKRevitTools.isRiserPipe(supplyPipe) && !YJKRevitTools.isRiserPipe(returnPipe))
				{
					if (!hypiping.IsParallel(hypiping2.Piping))
					{
						return RadiatorConnHelper.DoubleConnPipesType.HPipeNormal;
					}
					if (hypiping.IsParallel(connParam.OutPipe))
					{
						return this.DoublePlanePipeConnType(connParam, hypiping, hypiping2);
					}
					if (!hypiping.IsVertical(connParam.OutPipe))
					{
						return RadiatorConnHelper.DoubleConnPipesType.Invalid;
					}
					result = this.CheckDoubleHPipeConnType(connParam, hypiping, hypiping2);
				}
				return result;
			}
			if (!hypiping.IsParallel(hypiping2.Piping))
			{
				return RadiatorConnHelper.DoubleConnPipesType.RPipeNormal;
			}
			return this.DoubleRiserPipeConnType(connParam, hypiping, hypiping2);
		}

		private RadiatorConnHelper.DoubleConnPipesType CheckDoubleHPipeConnType(RadiatorConnParam connParam, YJKPiping<Pipe> hySupplyPipe, YJKPiping<Pipe> hyReturnPipe)
		{
			double outerDiameter = hySupplyPipe.GetOuterDiameter();
			double outerDiameter2 = hyReturnPipe.GetOuterDiameter();
			double outerDiameter3 = new YJKPiping<Pipe>(connParam.InPipe).GetOuterDiameter();
			double outerDiameter4 = new YJKPiping<Pipe>(connParam.OutPipe).GetOuterDiameter();
			new YJKLine(connParam.InExPipeConn.Origin, connParam.InExPipeConn.Origin.Add(connParam.InExPipeConn.CoordinateSystem.BasisZ)).MakeUnBound();
			YJKLine hyline = new YJKLine(hySupplyPipe.StartConnector.Origin, hySupplyPipe.EndConnector.Origin);
			YJKLine hyline2 = new YJKLine(hyReturnPipe.StartConnector.Origin, hyReturnPipe.EndConnector.Origin);
			double z = connParam.InConnector.Origin.Z;
			double z2 = connParam.OutConnector.Origin.Z;
			double num = (z < z2) ? (z - outerDiameter3 / 2.0) : (z2 - outerDiameter4 / 2.0);
			double num2 = (z > z2) ? (z + outerDiameter3 / 2.0) : (z2 + outerDiameter4 / 2.0);
			double z3 = hySupplyPipe.StartConnector.Origin.Z;
			double z4 = hyReturnPipe.StartConnector.Origin.Z;
			YJKLine hyline3 = this.GetHYLine(hySupplyPipe, true);
			YJKLine hyline4 = this.GetHYLine(hyReturnPipe, true);
			double hplanerDistance = this.GetHPlanerDistance(connParam.InConnector.Origin, hyline2);
			double hplanerDistance2 = this.GetHPlanerDistance(connParam.OutConnector.Origin, hyline);
			double distance = hySupplyPipe.GetDistance(hyReturnPipe.Piping);
			if (distance < (outerDiameter / 2.0 + outerDiameter2 / 2.0) * 1.5)
			{
				return RadiatorConnHelper.DoubleConnPipesType.HPipeNormal;
			}
			if ((z3 - outerDiameter / 2.0 - num2 > this.m_precision && z4 - outerDiameter2 / 2.0 - num2 > this.m_precision) || (z3 + outerDiameter / 2.0 - num < this.m_precision && z4 + outerDiameter2 / 2.0 - num < this.m_precision))
			{
				if (hyline2.GetXYDistance(hyline.Line) == 0.0)
				{
					double distance2 = hyline3.GetDistance(connParam.InConnector.Origin);
					double distance3 = hyline4.GetDistance(connParam.InConnector.Origin);
					if (distance2 > distance3)
					{
						return RadiatorConnHelper.DoubleConnPipesType.HPipeOverIn2;
					}
					return RadiatorConnHelper.DoubleConnPipesType.HPipeOverOut2;
				}
			}
			else if (Math.Abs(z3 - z2) <= this.m_precision || Math.Abs(z4 - z) <= this.m_precision)
			{
				if (hyline2.GetXYDistance(hyline.Line) == 0.0)
				{
					if (Math.Abs(z - z2) > this.m_precision)
					{
						double minSingleElbowLength = RadiatorConnHelper.GetMinSingleElbowLength(outerDiameter2 / 2.0, outerDiameter3 / 2.0);
						double minSingleElbowLength2 = RadiatorConnHelper.GetMinSingleElbowLength(outerDiameter / 2.0, outerDiameter4 / 2.0);
						double minDoubleElbowLength = RadiatorConnHelper.GetMinDoubleElbowLength(outerDiameter2 / 2.0, outerDiameter / 2.0, outerDiameter3 / 2.0);
						double minDoubleElbowLength2 = RadiatorConnHelper.GetMinDoubleElbowLength(outerDiameter / 2.0, outerDiameter2 / 2.0, outerDiameter4 / 2.0);
						if (Math.Abs(z2 - z3) <= this.m_precision && Math.Abs(z - z4) <= this.m_precision)
						{
							if (hplanerDistance > minSingleElbowLength && distance > minDoubleElbowLength)
							{
								return RadiatorConnHelper.DoubleConnPipesType.HPipeDoubleElbow;
							}
							if (hplanerDistance > minSingleElbowLength && distance > minSingleElbowLength && distance < minDoubleElbowLength)
							{
								return RadiatorConnHelper.DoubleConnPipesType.HPipeSingleElbow;
							}
						}
						else if (Math.Abs(z - z4) <= this.m_precision)
						{
							if ((z3 < z4 && z3 > z2) || (z3 > z4 && z3 < z2))
							{
								if (hplanerDistance > minSingleElbowLength && distance > minSingleElbowLength && distance < minDoubleElbowLength)
								{
									return RadiatorConnHelper.DoubleConnPipesType.HPipeSingleElbowInAndOverOut;
								}
								if (hplanerDistance > minSingleElbowLength && distance > minDoubleElbowLength)
								{
									return RadiatorConnHelper.DoubleConnPipesType.HPipeDoubleElbowInAndOverOut;
								}
							}
							else
							{
								if (hplanerDistance > minSingleElbowLength && distance > minSingleElbowLength && distance < minDoubleElbowLength)
								{
									return RadiatorConnHelper.DoubleConnPipesType.HPipeSingleElbowIn;
								}
								if (hplanerDistance > minSingleElbowLength && distance > minDoubleElbowLength)
								{
									return RadiatorConnHelper.DoubleConnPipesType.HPipeDoubleElbowIn;
								}
							}
						}
						else if ((z4 < z3 && z4 > z) || (z4 > z3 && z4 < z))
						{
							if (hplanerDistance2 > minSingleElbowLength2 && distance > minSingleElbowLength2 && distance < minDoubleElbowLength2)
							{
								return RadiatorConnHelper.DoubleConnPipesType.HPipeSingleElbowOutAndOverIn;
							}
							if (hplanerDistance2 > minSingleElbowLength2 && distance > minDoubleElbowLength2)
							{
								return RadiatorConnHelper.DoubleConnPipesType.HPipeDoubleElbowOutAndOverIn;
							}
						}
						else
						{
							if (hplanerDistance2 > minSingleElbowLength2 && distance > minSingleElbowLength2 && distance < minDoubleElbowLength2)
							{
								return RadiatorConnHelper.DoubleConnPipesType.HPipeSingleElbowOut;
							}
							if (hplanerDistance2 > minSingleElbowLength2 && distance > minDoubleElbowLength2)
							{
								return RadiatorConnHelper.DoubleConnPipesType.HPipeDoubleElbowOut;
							}
						}
					}
				}
				else
				{
					double hdistance = this.GetHDistance(hyline3, connParam.InConnector.Origin);
					double hdistance2 = this.GetHDistance(hyline4, connParam.OutConnector.Origin);
					if (Math.Abs(z2 - z3) <= this.m_precision)
					{
						if (hdistance2 > hdistance)
						{
							return RadiatorConnHelper.DoubleConnPipesType.HPipeOverOut1;
						}
						if (Math.Abs(z - z4) <= this.m_precision)
						{
							return RadiatorConnHelper.DoubleConnPipesType.HPipeOverIn1;
						}
					}
					else if (Math.Abs(z - z4) <= this.m_precision)
					{
						if (hdistance > hdistance2)
						{
							return RadiatorConnHelper.DoubleConnPipesType.HPipeOverIn1;
						}
						if (Math.Abs(z2 - z3) <= this.m_precision)
						{
							return RadiatorConnHelper.DoubleConnPipesType.HPipeOverOut1;
						}
					}
				}
			}
			else
			{
				if (Math.Abs(z - z4) <= this.m_precision || Math.Abs(z2 - z3) <= this.m_precision)
				{
					return RadiatorConnHelper.DoubleConnPipesType.HPipeNormal;
				}
				if (hyline2.GetXYDistance(hyline.Line) == 0.0)
				{
					if (z > z2 && z4 > z3)
					{
						if (z4 > z && z3 > z2 && z3 < z)
						{
							return RadiatorConnHelper.DoubleConnPipesType.HPipeOverOut2;
						}
						if (z4 < z && z4 > z2 && z3 > z2)
						{
							return RadiatorConnHelper.DoubleConnPipesType.Invalid;
						}
						if (z4 < z && z4 > z2 && z3 < z2)
						{
							return RadiatorConnHelper.DoubleConnPipesType.HPipeOverIn2;
						}
					}
					else if (z2 > z && z3 > z4)
					{
						if (z3 > z2 && z4 < z2 && z4 > z)
						{
							return RadiatorConnHelper.DoubleConnPipesType.HPipeOverIn2;
						}
						if (z3 < z2 && z3 > z && z4 > z)
						{
							return RadiatorConnHelper.DoubleConnPipesType.Invalid;
						}
						if (z3 < z2 && z3 > z && z4 < z)
						{
							return RadiatorConnHelper.DoubleConnPipesType.HPipeOverOut2;
						}
					}
				}
			}
			return RadiatorConnHelper.DoubleConnPipesType.HPipeNormal;
		}

		private double GetHPlanerDistance(XYZ basePoint, YJKLine hyLine)
		{
			if (basePoint == null || hyLine == null)
			{
				return 0.0;
			}
			XYZ project = hyLine.GetProject(basePoint);
			XYZ xyz = new XYZ(project.X, project.Y, basePoint.Z);
			return basePoint.DistanceTo(xyz);
		}

		private double GetMinValue(double d1, double d2)
		{
			if (d1 > d2)
			{
				return d2;
			}
			return d1;
		}

		private double GetHDistance(YJKLine hyline, XYZ point)
		{
			double result = 0.0;
			if (hyline == null)
			{
				return result;
			}
			XYZ project = hyline.GetProject(point);
			XYZ xyz = new XYZ(project.X, project.Y, point.Z);
			return point.DistanceTo(xyz);
		}

		private YJKLine GetHYLine(YJKPiping<Pipe> hyMainDuct, bool zSetZero = true)
		{
			XYZ start;
			XYZ end;
			if (zSetZero)
			{
				start = YJKRevitTools.SetZToZero(hyMainDuct.StartConnector.Origin);
				end = YJKRevitTools.SetZToZero(hyMainDuct.EndConnector.Origin);
			}
			else
			{
				start = hyMainDuct.StartConnector.Origin;
				end = hyMainDuct.EndConnector.Origin;
			}
			YJKLine hyline = new YJKLine(start, end);
			hyline.MakeUnBound();
			return hyline;
		}

		public static double GetMinSingleElbowLength(double rAvoidMainPipe, double rBranchPipe)
		{
			return (rAvoidMainPipe + rBranchPipe) / Math.Sin(0.78539816339744828);
		}

		public static double GetMinDoubleElbowLength(double rAvoidMainPipe, double rConnMainPipe, double rBranchPipe)
		{
			double num = (rConnMainPipe + rBranchPipe) * RadiatorConnHelper.coeff + rAvoidMainPipe / Math.Sin(0.78539816339744828);
			double num2 = rBranchPipe * 16.0;
			if (num >= num2)
			{
				return num;
			}
			return num2;
		}

		private RadiatorConnHelper.DoubleConnPipesType DoubleRiserPipeConnType(RadiatorConnParam connParam, YJKPiping<Pipe> hySupplyPipe, YJKPiping<Pipe> hyReturnPipe)
		{
			double outerDiameter = hySupplyPipe.GetOuterDiameter();
			double outerDiameter2 = hyReturnPipe.GetOuterDiameter();
			double outerDiameter3 = new YJKPiping<Pipe>(connParam.InPipe).GetOuterDiameter();
			double outerDiameter4 = new YJKPiping<Pipe>(connParam.OutPipe).GetOuterDiameter();
			YJKLine hyline = new YJKLine(connParam.InExPipeConn.Origin, connParam.InExPipeConn.Origin.Add(connParam.InExPipeConn.CoordinateSystem.BasisZ));
			hyline.MakeUnBound();
			YJKLine hyline2 = new YJKLine(hySupplyPipe.StartConnector.Origin, hySupplyPipe.EndConnector.Origin);
			hyline2.MakeUnBound();
			YJKLine hyline3 = new YJKLine(hyReturnPipe.StartConnector.Origin, hyReturnPipe.EndConnector.Origin);
			hyline3.MakeUnBound();
			XYZ project = hyline.GetProject(hySupplyPipe.StartConnector.Origin);
			XYZ project2 = hyline.GetProject(hyReturnPipe.StartConnector.Origin);
			XYZ project3 = hyline2.GetProject(project);
			XYZ project4 = hyline3.GetProject(project2);
			XYZ xyz = project - project3;
			XYZ xyz2 = project2 - project4;
			XYZ xyz3 = new XYZ(0.0, 0.0, 0.0);
			if (xyz.DistanceTo(xyz3) < outerDiameter / 2.0 + outerDiameter4 / 2.0 && xyz2.DistanceTo(xyz3) < outerDiameter2 / 2.0 + outerDiameter3 / 2.0)
			{
				if (project.DistanceTo(connParam.InExPipeConn.Origin) < project2.DistanceTo(connParam.InExPipeConn.Origin))
				{
					return RadiatorConnHelper.DoubleConnPipesType.RPipeOverOut1;
				}
				return RadiatorConnHelper.DoubleConnPipesType.RPipeOverIn1;
			}
			else if (xyz.DistanceTo(xyz3) < outerDiameter / 2.0 + outerDiameter4 / 2.0 || xyz2.DistanceTo(xyz3) < outerDiameter2 / 2.0 + outerDiameter3 / 2.0)
			{
				if (xyz.DistanceTo(xyz3) < outerDiameter / 2.0 + outerDiameter4 / 2.0)
				{
					if (project.DistanceTo(project2) < (outerDiameter + outerDiameter2) / 2.0)
					{
						if (xyz2.DistanceTo(xyz3) > RadiatorConnHelper.GetMinDoubleElbowLength(outerDiameter / 2.0, outerDiameter2 / 2.0, outerDiameter4 / 2.0))
						{
							return RadiatorConnHelper.DoubleConnPipesType.RPipeDoubleElbowOut;
						}
						if (xyz2.DistanceTo(xyz3) > RadiatorConnHelper.GetMinSingleElbowLength(outerDiameter4 / 2.0, outerDiameter / 2.0))
						{
							return RadiatorConnHelper.DoubleConnPipesType.RPipeSingleElbowOut;
						}
						return RadiatorConnHelper.DoubleConnPipesType.RPipeNormal;
					}
					else
					{
						if (project.DistanceTo(connParam.InExPipeConn.Origin) < project2.DistanceTo(connParam.InExPipeConn.Origin))
						{
							return RadiatorConnHelper.DoubleConnPipesType.RPipeOverOut1;
						}
						return RadiatorConnHelper.DoubleConnPipesType.RPipeNormal;
					}
				}
				else if (project2.DistanceTo(project) < (outerDiameter + outerDiameter2) / 2.0)
				{
					if (xyz.DistanceTo(xyz3) > RadiatorConnHelper.GetMinDoubleElbowLength(outerDiameter2 / 2.0, outerDiameter / 2.0, outerDiameter3 / 2.0))
					{
						return RadiatorConnHelper.DoubleConnPipesType.RPipeDoubleElbowIn;
					}
					if (xyz.DistanceTo(xyz3) > RadiatorConnHelper.GetMinSingleElbowLength(outerDiameter3 / 2.0, outerDiameter2 / 2.0))
					{
						return RadiatorConnHelper.DoubleConnPipesType.RPipeSingleElbowIn;
					}
					return RadiatorConnHelper.DoubleConnPipesType.RPipeNormal;
				}
				else
				{
					if (project.DistanceTo(connParam.InExPipeConn.Origin) > project2.DistanceTo(connParam.InExPipeConn.Origin))
					{
						return RadiatorConnHelper.DoubleConnPipesType.RPipeOverIn1;
					}
					return RadiatorConnHelper.DoubleConnPipesType.RPipeNormal;
				}
			}
			else
			{
				if (!xyz.Normalize().IsAlmostEqualTo(xyz2.Normalize()))
				{
					return RadiatorConnHelper.DoubleConnPipesType.RPipeNormal;
				}
				if (project.DistanceTo(project2) >= (outerDiameter + outerDiameter2) / 2.0)
				{
					return RadiatorConnHelper.DoubleConnPipesType.RPipeNormal;
				}
				if (xyz.DistanceTo(xyz3) < xyz2.DistanceTo(xyz3))
				{
					return RadiatorConnHelper.DoubleConnPipesType.RPipeOverOut2;
				}
				return RadiatorConnHelper.DoubleConnPipesType.RPipeOverIn2;
			}
		}

		private RadiatorConnHelper.DoubleConnPipesType DoublePlanePipeConnType(RadiatorConnParam connParam, YJKPiping<Pipe> hySupplyPipe, YJKPiping<Pipe> hyReturnPipe)
		{
			double outerDiameter = hySupplyPipe.GetOuterDiameter();
			double outerDiameter2 = hyReturnPipe.GetOuterDiameter();
			double outerDiameter3 = new YJKPiping<Pipe>(connParam.InPipe).GetOuterDiameter();
			double outerDiameter4 = new YJKPiping<Pipe>(connParam.OutPipe).GetOuterDiameter();
			YJKLine hyline = new YJKLine(connParam.InExPipeConn.Origin, connParam.InExPipeConn.Origin.Add(connParam.InExPipeConn.CoordinateSystem.BasisZ));
			hyline.MakeUnBound();
			YJKLine hyline2 = new YJKLine(hySupplyPipe.StartConnector.Origin, hySupplyPipe.EndConnector.Origin);
			YJKLine hyline3 = new YJKLine(hyReturnPipe.StartConnector.Origin, hyReturnPipe.EndConnector.Origin);
			double z = connParam.InConnector.Origin.Z;
			double z2 = connParam.OutConnector.Origin.Z;
			double num = (z < z2) ? (z - outerDiameter3 / 2.0) : (z2 - outerDiameter4 / 2.0);
			double num2 = (z > z2) ? (z + outerDiameter3 / 2.0) : (z2 + outerDiameter4 / 2.0);
			double z3 = hySupplyPipe.StartConnector.Origin.Z;
			double z4 = hyReturnPipe.StartConnector.Origin.Z;
			if ((z3 - outerDiameter / 2.0 > num2 && z4 - outerDiameter2 / 2.0 > num2) || (z3 + outerDiameter / 2.0 < num && z4 - outerDiameter2 / 2.0 < num))
			{
				if (hyline.GetXYDistance(hyline2.Line) < (outerDiameter + outerDiameter4) / 2.0 && hyline.GetXYDistance(hyline3.Line) < (outerDiameter2 + outerDiameter3) / 2.0)
				{
					if (hyline.GetDistance(hySupplyPipe.StartConnector.Origin) < hyline.GetDistance(hyReturnPipe.StartConnector.Origin))
					{
						return RadiatorConnHelper.DoubleConnPipesType.HPipeOverOut1;
					}
					return RadiatorConnHelper.DoubleConnPipesType.HPipeOverIn1;
				}
				else
				{
					if (hyline.GetXYDistance(hyline2.Line) >= (outerDiameter + outerDiameter4) / 2.0 && hyline.GetXYDistance(hyline3.Line) >= (outerDiameter2 + outerDiameter3) / 2.0)
					{
						return this.GetHPipeType(hyline2, hyline3, connParam, z3, z4, outerDiameter, outerDiameter2);
					}
					if (hyline.GetXYDistance(hyline2.Line) < (outerDiameter + outerDiameter4) / 2.0)
					{
						if (Math.Abs(z3 - z4) < (outerDiameter + outerDiameter2) / 2.0)
						{
							if (hyline2.GetXYDistance(hyline3.Line) > RadiatorConnHelper.GetMinDoubleElbowLength(outerDiameter / 2.0, outerDiameter2 / 2.0, outerDiameter4 / 2.0))
							{
								return RadiatorConnHelper.DoubleConnPipesType.HPipeDoubleElbowOut;
							}
							if (hyline2.GetXYDistance(hyline3.Line) > RadiatorConnHelper.GetMinSingleElbowLength(outerDiameter4 / 2.0, outerDiameter / 2.0))
							{
								return RadiatorConnHelper.DoubleConnPipesType.HPipeSingleElbowOut;
							}
							return RadiatorConnHelper.DoubleConnPipesType.HPipeNormal;
						}
						else
						{
							if (Math.Abs(z4 - z) > Math.Abs(z3 - z))
							{
								return RadiatorConnHelper.DoubleConnPipesType.HPipeOverOut1;
							}
							return RadiatorConnHelper.DoubleConnPipesType.HPipeNormal;
						}
					}
					else if (Math.Abs(z3 - z4) < (outerDiameter + outerDiameter2) / 2.0)
					{
						if (hyline2.GetXYDistance(hyline3.Line) > RadiatorConnHelper.GetMinDoubleElbowLength(outerDiameter2 / 2.0, outerDiameter / 2.0, outerDiameter3 / 2.0))
						{
							return RadiatorConnHelper.DoubleConnPipesType.HPipeDoubleElbowIn;
						}
						if (hyline2.GetXYDistance(hyline3.Line) > RadiatorConnHelper.GetMinSingleElbowLength(outerDiameter3 / 2.0, outerDiameter2 / 2.0))
						{
							return RadiatorConnHelper.DoubleConnPipesType.HPipeSingleElbowIn;
						}
						return RadiatorConnHelper.DoubleConnPipesType.HPipeNormal;
					}
					else
					{
						if (Math.Abs(z4 - z) < Math.Abs(z3 - z))
						{
							return RadiatorConnHelper.DoubleConnPipesType.HPipeOverIn1;
						}
						return RadiatorConnHelper.DoubleConnPipesType.HPipeNormal;
					}
				}
			}
			else
			{
				if ((z3 - outerDiameter / 2.0 < num2 && z4 - outerDiameter2 / 2.0 < num2) || (z3 + outerDiameter / 2.0 > num && z4 - outerDiameter2 / 2.0 > num))
				{
					return this.GetHPipeType(hyline2, hyline3, connParam, z3, z4, outerDiameter, outerDiameter2);
				}
				if ((z3 - outerDiameter / 2.0 != num2 || z4 - outerDiameter2 / 2.0 != num2) && (z3 + outerDiameter / 2.0 != num || z4 - outerDiameter2 / 2.0 != num))
				{
					return RadiatorConnHelper.DoubleConnPipesType.HPipeNormal;
				}
				XYZ xyz = new XYZ(0.0, 0.0, 0.0);
				hyline2.MakeUnBound();
				hyline3.MakeUnBound();
				XYZ project = hyline2.GetProject(connParam.InExPipeConn.Origin);
				XYZ xyz2 = new XYZ(project.X - connParam.InExPipeConn.Origin.X, project.Y - connParam.InExPipeConn.Origin.Y, 0.0);
				XYZ project2 = hyline3.GetProject(connParam.InExPipeConn.Origin);
				XYZ xyz3 = new XYZ(project2.X - connParam.InExPipeConn.Origin.X, project2.Y - connParam.InExPipeConn.Origin.Y, 0.0);
				if (xyz2.DistanceTo(xyz) < xyz3.DistanceTo(xyz))
				{
					return RadiatorConnHelper.DoubleConnPipesType.HPipeOverOut1;
				}
				return RadiatorConnHelper.DoubleConnPipesType.HPipeOverIn1;
			}
		}

		private RadiatorConnHelper.DoubleConnPipesType GetHPipeType(YJKLine hySpLine, YJKLine hyRpLine, RadiatorConnParam connParam, double supplyPipeLevel, double returnPipeLevel, double spOutDia, double rpOutDia)
		{
			XYZ xyz = new XYZ(0.0, 0.0, 0.0);
			hySpLine.MakeUnBound();
			hyRpLine.MakeUnBound();
			XYZ project = hySpLine.GetProject(connParam.InExPipeConn.Origin);
			XYZ xyz2 = new XYZ(project.X - connParam.InExPipeConn.Origin.X, project.Y - connParam.InExPipeConn.Origin.Y, 0.0);
			XYZ project2 = hyRpLine.GetProject(connParam.InExPipeConn.Origin);
			XYZ xyz3 = new XYZ(project2.X - connParam.InExPipeConn.Origin.X, project2.Y - connParam.InExPipeConn.Origin.Y, 0.0);
			if (!xyz2.Normalize().IsAlmostEqualTo(xyz3.Normalize()) || Math.Abs(supplyPipeLevel - returnPipeLevel) >= (spOutDia + rpOutDia) / 2.0)
			{
				return RadiatorConnHelper.DoubleConnPipesType.HPipeNormal;
			}
			if (xyz2.DistanceTo(xyz) < xyz3.DistanceTo(xyz))
			{
				return RadiatorConnHelper.DoubleConnPipesType.HPipeOverOut2;
			}
			return RadiatorConnHelper.DoubleConnPipesType.HPipeOverIn2;
		}

		private bool ConnCrossPipes(List<RadiatorConnParam> radiatorSet, XYZ basePnt)
		{
			bool result = true;
			try
			{
				Pipe farPipeToPoint = this.SupplyPipe;
				foreach (RadiatorConnParam radiatorConnParam in radiatorSet)
				{
					if (!this.CheckPipeEquipmentRelation(radiatorConnParam.InConnector, farPipeToPoint))
					{
						throw new Exception("散热器连接口应与连接管道平行或垂直！");
					}
					double num = basePnt.DistanceTo(radiatorConnParam.PntOnPipeIn);
					double num2 = basePnt.DistanceTo(radiatorConnParam.PntOnPipeOut);
					if (num <= num2)
					{
						IList<Pipe> list = this.ConnPipe(radiatorConnParam, farPipeToPoint, 2);
						this.Doc.Regenerate();
						farPipeToPoint = this.GetFarPipeToPoint(list, basePnt);
						list = this.ConnPipe(radiatorConnParam, farPipeToPoint, 1);
						this.Doc.Regenerate();
						farPipeToPoint = this.GetFarPipeToPoint(list, basePnt);
					}
					else
					{
						IList<Pipe> list = this.ConnPipe(radiatorConnParam, farPipeToPoint, 1);
						this.Doc.Regenerate();
						farPipeToPoint = this.GetFarPipeToPoint(list, basePnt);
						list = this.ConnPipe(radiatorConnParam, farPipeToPoint, 2);
						this.Doc.Regenerate();
						farPipeToPoint = this.GetFarPipeToPoint(list, basePnt);
					}
					this.BranchPipeConn(radiatorConnParam);
				}
			}
			catch (Exception ex)
			{
				result = false;
				this.Message = ex.Message;
			}
			return result;
		}

		private bool ConnDownPipes(List<RadiatorConnParam> radiatorSet, XYZ basePnt)
		{
			bool result = true;
			try
			{
				Pipe farPipeToPoint = this.SupplyPipe;
				foreach (RadiatorConnParam radiatorConnParam in radiatorSet)
				{
					if (!this.CheckPipeEquipmentRelation(radiatorConnParam.InConnector, farPipeToPoint))
					{
						throw new Exception("散热器连接口应与连接管道平行或垂直！");
					}
					double num = basePnt.DistanceTo(radiatorConnParam.PntOnPipeIn);
					double num2 = basePnt.DistanceTo(radiatorConnParam.PntOnPipeOut);
					if (num <= num2)
					{
						IList<Pipe> list = this.ConnPipe(radiatorConnParam, farPipeToPoint, basePnt, 1, 2);
						this.Doc.Regenerate();
						farPipeToPoint = this.GetFarPipeToPoint(list, basePnt);
						list = this.ConnPipe(radiatorConnParam, farPipeToPoint, basePnt, 2, 1);
						this.Doc.Regenerate();
						farPipeToPoint = this.GetFarPipeToPoint(list, basePnt);
						if (list.Count > 1)
						{
							this.Doc.DeleteElement(this.GetPipeToPoint(list, basePnt, 2));
						}
						this.Doc.Regenerate();
					}
					else
					{
						IList<Pipe> list = this.ConnPipe(radiatorConnParam, farPipeToPoint, basePnt, 2, 2);
						this.Doc.Regenerate();
						farPipeToPoint = this.GetFarPipeToPoint(list, basePnt);
						list = this.ConnPipe(radiatorConnParam, farPipeToPoint, basePnt, 1, 1);
						this.Doc.Regenerate();
						farPipeToPoint = this.GetFarPipeToPoint(list, basePnt);
						if (list.Count > 1)
						{
							this.Doc.DeleteElement(this.GetPipeToPoint(list, basePnt, 2));
						}
						this.Doc.Regenerate();
					}
					this.BranchPipeConn(radiatorConnParam);
				}
			}
			catch (Exception ex)
			{
				result = false;
				this.Message = ex.Message;
			}
			return result;
		}

		private bool ConnDownPipes(RadiatorConnParam radiator)
		{
			bool result = true;
			try
			{
				bool beUp = true;
				bool beUp2 = true;
				this.JudgeConnPosition(radiator.ElementId, ref beUp, ref beUp2);
				Pipe pipeByOffset = this.SupplyPipe;
				double z = radiator.InConnector.Origin.Z;
				double z2 = radiator.OutConnector.Origin.Z;
				if (z <= z2)
				{
					IList<Pipe> list = this.ConnRiserPipes(radiator.OutPipe, pipeByOffset, 1, ref this.message, beUp);
					this.Doc.Regenerate();
					pipeByOffset = this.GetPipeByOffset(list, 2);
					if (pipeByOffset == null)
					{
						pipeByOffset = this.SupplyPipe;
					}
					list = this.ConnRiserPipes(radiator.InPipe, pipeByOffset, 2, ref this.message, beUp2);
					this.Doc.Regenerate();
					pipeByOffset = this.GetPipeByOffset(list, 1);
					if (list.Count > 1)
					{
						this.Doc.DeleteElement(pipeByOffset);
					}
					this.Doc.Regenerate();
				}
				else
				{
					IList<Pipe> list = this.ConnRiserPipes(radiator.InPipe, pipeByOffset, 1, ref this.message, beUp);
					this.Doc.Regenerate();
					pipeByOffset = this.GetPipeByOffset(list, 2);
					if (pipeByOffset == null)
					{
						pipeByOffset = this.SupplyPipe;
					}
					list = this.ConnRiserPipes(radiator.OutPipe, pipeByOffset, 2, ref this.message, beUp2);
					this.Doc.Regenerate();
					pipeByOffset = this.GetPipeByOffset(list, 1);
					if (list.Count > 1)
					{
						this.Doc.DeleteElement(pipeByOffset);
					}
					this.Doc.Regenerate();
				}
			}
			catch (Exception ex)
			{
				result = false;
				this.Message = ex.Message;
			}
			return result;
		}

		private bool ConnCrossPipes(RadiatorConnParam radiator)
		{
			bool result = true;
			try
			{
				bool beUp = true;
				bool beUp2 = true;
				this.JudgeConnPosition(radiator.ElementId, ref beUp, ref beUp2);
				Pipe pipeByOffset = this.SupplyPipe;
				double z = radiator.InConnector.Origin.Z;
				double z2 = radiator.OutConnector.Origin.Z;
				if (z <= z2)
				{
					IList<Pipe> list = this.ConnRiserPipes(radiator.OutPipe, pipeByOffset, ref this.message, beUp);
					this.Doc.Regenerate();
					pipeByOffset = this.GetPipeByOffset(list, 2);
					if (pipeByOffset == null)
					{
						pipeByOffset = this.SupplyPipe;
					}
					list = this.ConnRiserPipes(radiator.InPipe, pipeByOffset, ref this.message, beUp2);
					this.Doc.Regenerate();
					pipeByOffset = this.GetPipeByOffset(list, 1);
					this.Doc.Regenerate();
				}
				else
				{
					IList<Pipe> list = this.ConnRiserPipes(radiator.InPipe, pipeByOffset, ref this.message, beUp);
					this.Doc.Regenerate();
					pipeByOffset = this.GetPipeByOffset(list, 2);
					if (pipeByOffset == null)
					{
						pipeByOffset = this.SupplyPipe;
					}
					list = this.ConnRiserPipes(radiator.OutPipe, pipeByOffset, ref this.message, beUp2);
					this.Doc.Regenerate();
					pipeByOffset = this.GetPipeByOffset(list, 1);
					this.Doc.Regenerate();
				}
			}
			catch (Exception ex)
			{
				result = false;
				this.Message = ex.Message;
			}
			return result;
		}

		private bool ConnDoublePipes(RadiatorConnParam radiator)
		{
			bool result = true;
			try
			{
				bool beUp = true;
				bool beUp2 = true;
				this.JudgeConnPosition(radiator.ElementId, ref beUp, ref beUp2);
				Pipe pipe = this.SupplyPipe;
				Pipe pipe2 = this.ReturnPipe;
				RadiatorConnHelper.DoubleConnPipesType doubleConnPipesType = this.DistinguishConnStyle(radiator, pipe, pipe2);
				switch (doubleConnPipesType)
				{
				case RadiatorConnHelper.DoubleConnPipesType.RPipeNormal:
					this.ConnRiserPipes(radiator.OutPipe, pipe2, ref this.message, beUp2);
					this.Doc.Regenerate();
					this.ConnRiserPipes(radiator.InPipe, pipe, ref this.message, beUp);
					this.Doc.Regenerate();
					break;
				case RadiatorConnHelper.DoubleConnPipesType.RPipeOverIn1:
					this.ConnRPipesOver1(radiator.InPipe, pipe, pipe2, -radiator.FacingOrientation, ref this.message, beUp);
					this.Doc.Regenerate();
					this.ConnRiserPipes(radiator.OutPipe, pipe2, ref this.message, beUp2);
					this.Doc.Regenerate();
					break;
				case RadiatorConnHelper.DoubleConnPipesType.RPipeOverIn2:
					this.ConnRPipesOver2(radiator.InPipe, pipe, pipe2, ref this.message, beUp);
					this.Doc.Regenerate();
					this.ConnRiserPipes(radiator.OutPipe, pipe2, ref this.message, beUp2);
					this.Doc.Regenerate();
					break;
				case RadiatorConnHelper.DoubleConnPipesType.RPipeOverOut1:
					this.ConnRPipesOver1(radiator.OutPipe, pipe2, pipe, -radiator.FacingOrientation, ref this.message, beUp2);
					this.Doc.Regenerate();
					this.ConnRiserPipes(radiator.InPipe, pipe, ref this.message, beUp);
					this.Doc.Regenerate();
					break;
				case RadiatorConnHelper.DoubleConnPipesType.RPipeOverOut2:
					this.ConnRPipesOver2(radiator.OutPipe, pipe2, pipe, ref this.message, beUp2);
					this.Doc.Regenerate();
					this.ConnRiserPipes(radiator.InPipe, pipe, ref this.message, beUp);
					this.Doc.Regenerate();
					break;
				case RadiatorConnHelper.DoubleConnPipesType.RPipeDoubleElbowIn:
					this.ConnRPipesDoubleElbow(radiator.InPipe, pipe, pipe2, ref this.message, beUp);
					this.Doc.Regenerate();
					this.ConnRiserPipes(radiator.OutPipe, pipe2, ref this.message, beUp2);
					this.Doc.Regenerate();
					break;
				case RadiatorConnHelper.DoubleConnPipesType.RPipeDoubleElbowOut:
					this.ConnRPipesDoubleElbow(radiator.OutPipe, pipe2, pipe, ref this.message, beUp2);
					this.Doc.Regenerate();
					this.ConnRiserPipes(radiator.InPipe, pipe, ref this.message, beUp);
					this.Doc.Regenerate();
					break;
				case RadiatorConnHelper.DoubleConnPipesType.RPipeSingleElbowIn:
					this.ConnRPipesSingleElbow(radiator.InPipe, pipe, pipe2, ref this.message, beUp);
					this.Doc.Regenerate();
					this.ConnRiserPipes(radiator.OutPipe, pipe2, ref this.message, beUp2);
					this.Doc.Regenerate();
					break;
				case RadiatorConnHelper.DoubleConnPipesType.RPipeSingleElbowOut:
					this.ConnRPipesSingleElbow(radiator.OutPipe, pipe2, pipe, ref this.message, beUp2);
					this.Doc.Regenerate();
					this.ConnRiserPipes(radiator.InPipe, pipe, ref this.message, beUp);
					this.Doc.Regenerate();
					break;
				default:
					if (doubleConnPipesType != RadiatorConnHelper.DoubleConnPipesType.Invalid)
					{
					}
					break;
				}
				if (this.message != "")
				{
					result = false;
				}
			}
			catch (Exception ex)
			{
				result = false;
				this.Message = ex.Message;
			}
			return result;
		}

		private IList<Pipe> ConnPipe(RadiatorConnParam radiatorConn, Pipe pipe, XYZ basePnt, int styleNum, int connNum)
		{
			IList<Pipe> list = new List<Pipe>();
			if (pipe == null)
			{
				return list;
			}
			Pipe pipe2;
			Pipe otherSidePipe;
			if (styleNum == 1)
			{
				pipe2 = radiatorConn.InPipe;
				otherSidePipe = radiatorConn.OutPipe;
			}
			else
			{
				pipe2 = radiatorConn.OutPipe;
				otherSidePipe = radiatorConn.InPipe;
			}
			if (radiatorConn.ReDirection == 0)
			{
				list = this.ConnectParallelPipes(pipe2, pipe, basePnt, connNum, ref this.message, otherSidePipe);
			}
			else
			{
				list = this.ConnInterSectionPipes(pipe2, pipe, basePnt, connNum, ref this.message);
			}
			if (list == null || list.Count < 1)
			{
				list = new List<Pipe>();
				list.Add(pipe);
			}
			return list;
		}

		private IList<Pipe> ConnPipe(RadiatorConnParam radiatorConn, Pipe pipe, int styleNum)
		{
			IList<Pipe> result = new List<Pipe>();
			if (pipe == null)
			{
				return result;
			}
			Pipe pipe2;
			Pipe otherSidePipe;
			if (styleNum == 2)
			{
				pipe2 = radiatorConn.InPipe;
				otherSidePipe = radiatorConn.OutPipe;
			}
			else
			{
				pipe2 = radiatorConn.OutPipe;
				otherSidePipe = radiatorConn.InPipe;
			}
			if (radiatorConn.ReDirection == 0)
			{
				result = this.ConnectParallelPipes(pipe2, pipe, ref this.message, otherSidePipe);
			}
			else
			{
				result = this.ConnInterSectionPipes(pipe2, pipe, ref this.message);
			}
			return result;
		}

		private IList<Pipe> ConnPipeOver1(RadiatorConnParam radiatorConn, Pipe pipe, int styleNum, Pipe overPipe)
		{
			IList<Pipe> result = new List<Pipe>();
			if (pipe == null)
			{
				return result;
			}
			Pipe pipe2;
			Pipe otherSidePipe;
			XYZ hoverBridgeVector;
			if (styleNum == 2)
			{
				pipe2 = radiatorConn.InPipe;
				otherSidePipe = radiatorConn.OutPipe;
				hoverBridgeVector = this.GetHOverBridgeVector(overPipe, radiatorConn.OutConnector.Origin);
			}
			else
			{
				pipe2 = radiatorConn.OutPipe;
				otherSidePipe = radiatorConn.InPipe;
				hoverBridgeVector = this.GetHOverBridgeVector(overPipe, radiatorConn.InConnector.Origin);
			}
			if (radiatorConn.ReDirection == 0)
			{
				result = this.ConnectParallelPipesOver1(pipe2, pipe, ref this.message, overPipe, -radiatorConn.FacingOrientation, otherSidePipe);
			}
			else
			{
				result = new RadiatorConnHPipesHelper(this.riserPipe).ConnPipesByOverBridge(pipe2, pipe, overPipe, hoverBridgeVector, ref this.message);
			}
			return result;
		}

		private IList<Pipe> ConnPipeOver2(RadiatorConnParam radiatorConn, Pipe pipe, int styleNum, Pipe overPipe)
		{
			IList<Pipe> result = new List<Pipe>();
			if (pipe == null)
			{
				return result;
			}
			Pipe pipe2;
			Pipe otherSidePipe;
			XYZ overVector;
			if (styleNum == 2)
			{
				pipe2 = radiatorConn.InPipe;
				otherSidePipe = radiatorConn.OutPipe;
				overVector = radiatorConn.OutConnector.CoordinateSystem.BasisZ.Normalize();
			}
			else
			{
				pipe2 = radiatorConn.OutPipe;
				otherSidePipe = radiatorConn.InPipe;
				overVector = radiatorConn.InConnector.CoordinateSystem.BasisZ.Normalize();
			}
			if (radiatorConn.ReDirection == 0)
			{
				result = this.ConnectParallelPipesOver2(pipe2, pipe, ref this.message, overPipe, otherSidePipe);
			}
			else
			{
				result = new RadiatorConnHPipesHelper(this.riserPipe).ConnPipesByOverBridge(pipe2, pipe, overPipe, overVector, ref this.message);
			}
			return result;
		}

		private XYZ GetHOverBridgeVector(Pipe overPipe, XYZ point)
		{
			if (overPipe == null)
			{
				return null;
			}
			YJKPiping<Pipe> hypiping = new YJKPiping<Pipe>(overPipe);
			XYZ project = new YJKLine(hypiping.StartConnector.Origin, hypiping.EndConnector.Origin).GetProject(point);
			XYZ xyz = new XYZ(project.X, project.Y, point.Z);
			if (xyz.IsAlmostEqualTo(project, this.m_precision))
			{
				return null;
			}
			return project.Subtract(xyz).Normalize();
		}

		private XYZ GetROverBridgeVector(Pipe overPipe, XYZ point)
		{
			if (overPipe == null)
			{
				return null;
			}
			YJKPiping<Pipe> hypiping = new YJKPiping<Pipe>(overPipe);
			XYZ project = new YJKLine(hypiping.StartConnector.Origin, hypiping.EndConnector.Origin).GetProject(point);
			XYZ xyz = new XYZ(project.X, project.Y, point.Z);
			if (xyz.IsAlmostEqualTo(project, this.m_precision))
			{
				return null;
			}
			return xyz.Subtract(point).Normalize();
		}

		private IList<Pipe> ConnPipeDoubleElbow(RadiatorConnParam radiatorConn, Pipe pipe, int styleNum, Pipe overPipe)
		{
			IList<Pipe> result = new List<Pipe>();
			if (pipe == null)
			{
				return result;
			}
			Pipe pipe2;
			Pipe otherSidePipe;
			if (styleNum == 2)
			{
				pipe2 = radiatorConn.InPipe;
				otherSidePipe = radiatorConn.OutPipe;
			}
			else
			{
				pipe2 = radiatorConn.OutPipe;
				otherSidePipe = radiatorConn.InPipe;
			}
			if (radiatorConn.ReDirection == 0)
			{
				result = this.ConnectParallelPipesDoubleElbow(pipe2, pipe, ref this.message, overPipe, otherSidePipe);
			}
			else
			{
				result = new RadiatorConnHPipesHelper(this.riserPipe).ConnPipesByDoubleElbow(pipe2, pipe, overPipe, ref this.message);
			}
			return result;
		}

		private IList<Pipe> ConnPipeSingleElbow(RadiatorConnParam radiatorConn, Pipe pipe, int styleNum, Pipe pipe1)
		{
			IList<Pipe> result = new List<Pipe>();
			if (pipe == null)
			{
				return result;
			}
			Pipe pipe2;
			Pipe otherSidePipe;
			if (styleNum == 2)
			{
				pipe2 = radiatorConn.InPipe;
				otherSidePipe = radiatorConn.OutPipe;
			}
			else
			{
				pipe2 = radiatorConn.OutPipe;
				otherSidePipe = radiatorConn.InPipe;
			}
			if (radiatorConn.ReDirection == 0)
			{
				result = this.ConnectParallelPipesSingleElbow(pipe2, pipe, ref this.message, pipe1, otherSidePipe);
			}
			else
			{
				result = new RadiatorConnHPipesHelper(this.riserPipe).ConnPipesBySingleElbow(pipe2, pipe, pipe1, ref this.message);
			}
			return result;
		}

		private void MovePipe(ref XYZ facePoint, ref XYZ proPoint, XYZ connPoint, Pipe mainPipe)
		{
			YJKRotateFamilyInstance hyrotateFamilyInstance = new YJKRotateFamilyInstance();
			XYZ moveVector = facePoint.Subtract(proPoint);
			hyrotateFamilyInstance.MoveElement(moveVector, mainPipe);
			this.doc.Regenerate();
			YJKPiping<Pipe> hypiping = new YJKPiping<Pipe>(mainPipe);
			YJKLine hyline = new YJKLine(hypiping.StartConnector.Origin, hypiping.EndConnector.Origin);
			proPoint = hyline.GetProject(connPoint);
			facePoint = new XYZ(connPoint.X, connPoint.Y, proPoint.Z);
		}

		private List<Pipe> ConnectParallelPipes(Pipe sidePipe, Pipe mainPipe, ref string connMSG, Pipe otherSidePipe)
		{
			YJKPiping<Pipe> hypiping = new YJKPiping<Pipe>(sidePipe);
			YJKPiping<Pipe> hypiping2 = new YJKPiping<Pipe>(mainPipe);
			YJKLine hyline = new YJKLine(hypiping2.StartConnector.Origin, hypiping2.EndConnector.Origin);
			List<Pipe> result = new List<Pipe>();
			Document document = mainPipe.Document;
			XYZ xyz = hypiping.StartConnector.Connector.IsConnected ? hypiping.EndConnector.Origin : hypiping.StartConnector.Origin;
			double diameter = hypiping.GetDiameter();
			double diameter2 = hypiping2.GetDiameter();
			hyline.MakeUnBound();
			XYZ project = hyline.GetProject(xyz);
			XYZ xyz2 = new XYZ(xyz.X, xyz.Y, project.Z);
			double num = xyz.DistanceTo(xyz2);
			double num2 = xyz2.DistanceTo(project);
			double num3 = 0.016404199475065617;
			double num4 = (diameter + diameter2) * 2.0;
			if (num <= num3)
			{
				if (num2 < num4)
				{
					connMSG = "两管间距不合适，不能进行连接";
					return result;
				}
				Pipe pipe = YJKRevitTools.NewPipe(hypiping.Piping, xyz, project);
				this.SetDiameter(pipe, diameter);
				this.ConnPipeByEblow(pipe, hypiping.Piping);
				result = this.ConnectMainPipe(hyline, hypiping2, project, pipe);
			}
			else if (num >= num4)
			{
				if (num2 <= num3)
				{
					this.MovePipe(ref xyz2, ref project, xyz, mainPipe);
					hypiping2 = new YJKPiping<Pipe>(mainPipe);
					hyline = new YJKLine(hypiping2.StartConnector.Origin, hypiping2.EndConnector.Origin);
					Pipe pipe2 = YJKRevitTools.NewPipe(hypiping.Piping, xyz, project);
					this.SetDiameter(pipe2, diameter);
					this.ConnPipeByEblow(pipe2, hypiping.Piping);
					result = this.ConnectMainPipe(hyline, hypiping2, project, pipe2);
					this.riserPipe.Add(pipe2);
				}
				else
				{
					if (num2 < num4)
					{
						connMSG = "两管间距不合适，不能进行连接";
						return result;
					}
					Pipe pipe = YJKRevitTools.NewPipe(hypiping.Piping, xyz, xyz2);
					this.SetDiameter(pipe, diameter);
					this.ConnPipeByEblow(pipe, hypiping.Piping);
					Pipe pipe2 = YJKRevitTools.NewPipe(hypiping.Piping, xyz2, project);
					this.SetDiameter(pipe2, diameter);
					this.SidePipeDoubleElbowConn(xyz2, otherSidePipe, pipe2, pipe, ref connMSG);
					result = this.ConnectMainPipe(hyline, hypiping2, project, pipe2);
					this.riserPipe.Add(pipe);
				}
			}
			else
			{
				connMSG = "两管间距不合适，不能进行连接";
			}
			return result;
		}

		private void SidePipeDoubleElbowConn(XYZ facePoint, Pipe otherSidePipe, Pipe pipe1, Pipe pipe2, ref string msg)
		{
			YJKPiping<Pipe> hypiping = new YJKPiping<Pipe>(otherSidePipe);
			if (hypiping.GetProject(facePoint).DistanceTo(facePoint) < hypiping.GetDiameter())
			{
				new HYPipeConnect().NewElbowConnect(pipe1, pipe2, otherSidePipe, this.Doc, ref msg);
				return;
			}
			this.ConnPipeByEblow(pipe1, pipe2);
		}

		private List<Pipe> ConnectParallelPipesOver1(Pipe sidePipe, Pipe mainPipe, ref string connMSG, Pipe pipe1, XYZ facingOrient, Pipe otherSidePipe)
		{
			YJKPiping<Pipe> hypiping = new YJKPiping<Pipe>(sidePipe);
			YJKPiping<Pipe> hypiping2 = new YJKPiping<Pipe>(mainPipe);
			YJKLine hyline = new YJKLine(hypiping2.StartConnector.Origin, hypiping2.EndConnector.Origin);
			List<Pipe> result = new List<Pipe>();
			Document document = mainPipe.Document;
			XYZ xyz = hypiping.StartConnector.Connector.IsConnected ? hypiping.EndConnector.Origin : hypiping.StartConnector.Origin;
			double diameter = hypiping.GetDiameter();
			double diameter2 = hypiping2.GetDiameter();
			hyline.MakeUnBound();
			XYZ project = hyline.GetProject(xyz);
			XYZ xyz2 = new XYZ(xyz.X, xyz.Y, project.Z);
			double num = xyz.DistanceTo(xyz2);
			double num2 = xyz2.DistanceTo(project);
			double num3 = 0.016404199475065617;
			double num4 = (diameter + diameter2) * 2.0;
			if (num <= num3)
			{
				if (num2 < num4)
				{
					connMSG = "两管间距不合适，不能进行连接";
					return result;
				}
				Pipe pipe2 = YJKRevitTools.NewPipe(hypiping.Piping, xyz, project);
				this.SetDiameter(pipe2, diameter);
				this.ConnPipeByEblow(pipe2, hypiping.Piping);
				result = this.ConnectMainPipe(hyline, hypiping2, project, pipe2);
				HYPipeConnect hypipeConnect = new HYPipeConnect();
				List<Pipe> list = new List<Pipe>();
				XYZ unitVector = new XYZ(0.0, 0.0, -1.0);
				hypipeConnect.NewUnionFittings(pipe2, pipe1, document, unitVector, ref connMSG, ref list);
			}
			else if (num >= num4)
			{
				if (num2 <= num3)
				{
					this.MovePipe(ref xyz2, ref project, xyz, mainPipe);
					hypiping2 = new YJKPiping<Pipe>(mainPipe);
					hyline = new YJKLine(hypiping2.StartConnector.Origin, hypiping2.EndConnector.Origin);
					Pipe pipe3 = YJKRevitTools.NewPipe(hypiping.Piping, xyz, project);
					this.SetDiameter(pipe3, diameter);
					this.ConnPipeByEblow(pipe3, hypiping.Piping);
					result = this.ConnectMainPipe(hyline, hypiping2, project, pipe3);
					HYPipeConnect hypipeConnect2 = new HYPipeConnect();
					List<Pipe> collection = new List<Pipe>();
					hypipeConnect2.NewUnionFittings(pipe3, pipe1, document, facingOrient, ref connMSG, ref collection);
					this.riserPipe.AddRange(collection);
				}
				else
				{
					if (num2 < num4)
					{
						connMSG = "两管间距不合适，不能进行连接";
						return result;
					}
					Pipe pipe2 = YJKRevitTools.NewPipe(hypiping.Piping, xyz, xyz2);
					this.SetDiameter(pipe2, diameter);
					this.ConnPipeByEblow(pipe2, hypiping.Piping);
					Pipe pipe3 = YJKRevitTools.NewPipe(hypiping.Piping, xyz2, project);
					this.SetDiameter(pipe3, diameter);
					this.SidePipeDoubleElbowConn(xyz2, otherSidePipe, pipe3, pipe2, ref connMSG);
					result = this.ConnectMainPipe(hyline, hypiping2, project, pipe3);
					HYPipeConnect hypipeConnect3 = new HYPipeConnect();
					List<Pipe> collection2 = new List<Pipe>();
					hypipeConnect3.NewUnionFittings(pipe2, pipe1, document, facingOrient, ref connMSG, ref collection2);
					this.riserPipe.AddRange(collection2);
				}
			}
			else
			{
				connMSG = "两管间距不合适，不能进行连接";
			}
			return result;
		}

		private List<Pipe> ConnectParallelPipesOver2(Pipe sidePipe, Pipe mainPipe, ref string connMSG, Pipe pipe1, Pipe otherSidePipe)
		{
			YJKPiping<Pipe> hypiping = new YJKPiping<Pipe>(sidePipe);
			YJKPiping<Pipe> hypiping2 = new YJKPiping<Pipe>(mainPipe);
			YJKLine hyline = new YJKLine(hypiping2.StartConnector.Origin, hypiping2.EndConnector.Origin);
			List<Pipe> result = new List<Pipe>();
			Document document = mainPipe.Document;
			XYZ xyz = hypiping.StartConnector.Connector.IsConnected ? hypiping.EndConnector.Origin : hypiping.StartConnector.Origin;
			double diameter = hypiping.GetDiameter();
			double diameter2 = hypiping2.GetDiameter();
			hyline.MakeUnBound();
			XYZ project = hyline.GetProject(xyz);
			XYZ xyz2 = new XYZ(xyz.X, xyz.Y, project.Z);
			double num = xyz.DistanceTo(xyz2);
			double num2 = xyz2.DistanceTo(project);
			double num3 = 0.016404199475065617;
			double num4 = (diameter + diameter2) * 2.0;
			if (num <= num3)
			{
				if (num2 < num4)
				{
					connMSG = "两管间距不合适，不能进行连接";
					return result;
				}
				Pipe pipe2 = YJKRevitTools.NewPipe(hypiping.Piping, xyz, project);
				this.SetDiameter(pipe2, diameter);
				this.ConnPipeByEblow(pipe2, hypiping.Piping);
				result = this.ConnectMainPipe(hyline, hypiping2, project, pipe2);
				HYPipeConnect hypipeConnect = new HYPipeConnect();
				List<Pipe> list = new List<Pipe>();
				XYZ unitVector = new XYZ(0.0, 0.0, -1.0);
				hypipeConnect.NewUnionFittings(pipe2, pipe1, document, unitVector, ref connMSG, ref list);
			}
			else if (num >= num4)
			{
				if (num2 <= num3)
				{
					this.MovePipe(ref xyz2, ref project, xyz, mainPipe);
					hypiping2 = new YJKPiping<Pipe>(mainPipe);
					hyline = new YJKLine(hypiping2.StartConnector.Origin, hypiping2.EndConnector.Origin);
					Pipe pipe3 = YJKRevitTools.NewPipe(hypiping.Piping, xyz, project);
					this.SetDiameter(pipe3, diameter);
					this.ConnPipeByEblow(pipe3, hypiping.Piping);
					result = this.ConnectMainPipe(hyline, hypiping2, project, pipe3);
					this.riserPipe.Add(pipe3);
				}
				else
				{
					if (num2 < num4)
					{
						connMSG = "两管间距不合适，不能进行连接";
						return result;
					}
					Pipe pipe2 = YJKRevitTools.NewPipe(hypiping.Piping, xyz, xyz2);
					this.SetDiameter(pipe2, diameter);
					this.ConnPipeByEblow(pipe2, hypiping.Piping);
					Pipe pipe3 = YJKRevitTools.NewPipe(hypiping.Piping, xyz2, project);
					this.SetDiameter(pipe3, diameter);
					this.SidePipeDoubleElbowConn(xyz2, otherSidePipe, pipe3, pipe2, ref connMSG);
					result = this.ConnectMainPipe(hyline, hypiping2, project, pipe3);
					this.riserPipe.Add(pipe2);
					HYPipeConnect hypipeConnect2 = new HYPipeConnect();
					List<Pipe> list2 = new List<Pipe>();
					XYZ unitVector2 = new XYZ(0.0, 0.0, -1.0);
					hypipeConnect2.NewUnionFittings(pipe3, pipe1, document, unitVector2, ref connMSG, ref list2);
				}
			}
			else
			{
				connMSG = "两管间距不合适，不能进行连接";
			}
			return result;
		}

		private List<Pipe> ConnectParallelPipesDoubleElbow(Pipe sidePipe, Pipe mainPipe, ref string connMSG, Pipe pipe1, Pipe otherSidePipe)
		{
			YJKPiping<Pipe> hypiping = new YJKPiping<Pipe>(sidePipe);
			YJKPiping<Pipe> hypiping2 = new YJKPiping<Pipe>(mainPipe);
			YJKPiping<Pipe> hypiping3 = new YJKPiping<Pipe>(pipe1);
			YJKLine hyline = new YJKLine(hypiping2.StartConnector.Origin, hypiping2.EndConnector.Origin);
			List<Pipe> result = new List<Pipe>();
			Document document = mainPipe.Document;
			XYZ xyz = hypiping.StartConnector.Connector.IsConnected ? hypiping.EndConnector.Origin : hypiping.StartConnector.Origin;
			double diameter = hypiping.GetDiameter();
			hypiping2.GetDiameter();
			double rBranchPipe = hypiping.GetOuterDiameter() / 2.0;
			double rConnMainPipe = hypiping2.GetOuterDiameter() / 2.0;
			double rAvoidMainPipe = hypiping3.GetOuterDiameter() / 2.0;
			hyline.MakeUnBound();
			XYZ project = hyline.GetProject(xyz);
			XYZ xyz2 = new XYZ(xyz.X, xyz.Y, project.Z);
			double num = xyz.DistanceTo(xyz2);
			double num2 = xyz2.DistanceTo(project);
			double num3 = 0.016404199475065617;
			double minDoubleElbowLength = RadiatorConnHelper.GetMinDoubleElbowLength(rAvoidMainPipe, rConnMainPipe, rBranchPipe);
			if (num <= num3)
			{
				if (num2 < minDoubleElbowLength)
				{
					connMSG = "两管间距不合适，不能进行连接";
					return result;
				}
				Pipe pipe2 = YJKRevitTools.NewPipe(hypiping.Piping, xyz, project);
				this.SetDiameter(pipe2, diameter);
				this.ConnPipeByEblow(pipe2, hypiping.Piping);
				result = this.ConnectMainPipe(hyline, hypiping2, project, pipe2);
			}
			else if (num >= minDoubleElbowLength)
			{
				if (num2 <= num3)
				{
					this.MovePipe(ref xyz2, ref project, xyz, mainPipe);
					hypiping2 = new YJKPiping<Pipe>(mainPipe);
					hyline = new YJKLine(hypiping2.StartConnector.Origin, hypiping2.EndConnector.Origin);
					Pipe pipe3 = YJKRevitTools.NewPipe(hypiping.Piping, xyz, project);
					this.SetDiameter(pipe3, diameter);
					this.ConnPipeByEblow(pipe3, hypiping.Piping);
					result = this.ConnectMainPipe(hyline, hypiping2, project, pipe3);
					this.riserPipe.Add(pipe3);
				}
				else
				{
					if (num2 < minDoubleElbowLength)
					{
						connMSG = "两管间距不合适，不能进行连接";
						return result;
					}
					Pipe pipe2 = YJKRevitTools.NewPipe(hypiping.Piping, xyz, xyz2);
					this.SetDiameter(pipe2, diameter);
					this.ConnPipeByEblow(pipe2, hypiping.Piping);
					Pipe pipe3 = YJKRevitTools.NewPipe(hypiping.Piping, xyz2, project);
					this.SetDiameter(pipe3, diameter);
					new HYPipeConnect().NewElbowConnect(pipe2, pipe3, pipe1, document, ref connMSG);
					result = this.ConnectMainPipe(hyline, hypiping2, project, pipe3);
					this.riserPipe.Add(pipe2);
				}
			}
			else
			{
				connMSG = "两管间距不合适，不能进行连接";
			}
			return result;
		}

		private List<Pipe> ConnectParallelPipesSingleElbow(Pipe sidePipe, Pipe mainPipe, ref string connMSG, Pipe pipe1, Pipe otherSidePipe)
		{
			YJKPiping<Pipe> hypiping = new YJKPiping<Pipe>(sidePipe);
			YJKPiping<Pipe> hypiping2 = new YJKPiping<Pipe>(mainPipe);
			YJKPiping<Pipe> hypiping3 = new YJKPiping<Pipe>(pipe1);
			YJKLine hyline = new YJKLine(hypiping2.StartConnector.Origin, hypiping2.EndConnector.Origin);
			List<Pipe> result = new List<Pipe>();
			Document document = mainPipe.Document;
			XYZ xyz = hypiping.StartConnector.Connector.IsConnected ? hypiping.EndConnector.Origin : hypiping.StartConnector.Origin;
			double diameter = hypiping.GetDiameter();
			hypiping2.GetDiameter();
			double rAvoidMainPipe = hypiping.GetOuterDiameter() / 2.0;
			double rBranchPipe = hypiping3.GetOuterDiameter() / 2.0;
			hyline.MakeUnBound();
			XYZ project = hyline.GetProject(xyz);
			XYZ xyz2 = new XYZ(xyz.X, xyz.Y, project.Z);
			double num = xyz.DistanceTo(xyz2);
			double num2 = xyz2.DistanceTo(project);
			double num3 = 0.016404199475065617;
			double minSingleElbowLength = RadiatorConnHelper.GetMinSingleElbowLength(rAvoidMainPipe, rBranchPipe);
			XYZ xyz3 = new XYZ(0.0, 0.0, xyz.Z - project.Z);
			XYZ xyz4 = xyz2.Add(xyz3.Normalize() * num2);
			if (num <= num3)
			{
				if (num2 < minSingleElbowLength)
				{
					connMSG = "两管间距不合适，不能进行连接";
					return result;
				}
				Pipe pipe2 = YJKRevitTools.NewPipe(hypiping.Piping, xyz, project);
				this.SetDiameter(pipe2, diameter);
				this.ConnPipeByEblow(pipe2, hypiping.Piping);
				result = this.ConnectMainPipe(hyline, hypiping2, project, pipe2);
			}
			else if (num >= minSingleElbowLength)
			{
				if (num2 <= num3)
				{
					this.MovePipe(ref xyz2, ref project, xyz, mainPipe);
					hypiping2 = new YJKPiping<Pipe>(mainPipe);
					hyline = new YJKLine(hypiping2.StartConnector.Origin, hypiping2.EndConnector.Origin);
					Pipe pipe3 = YJKRevitTools.NewPipe(hypiping.Piping, xyz, project);
					this.SetDiameter(pipe3, diameter);
					this.ConnPipeByEblow(pipe3, hypiping.Piping);
					result = this.ConnectMainPipe(hyline, hypiping2, project, pipe3);
					this.riserPipe.Add(pipe3);
				}
				else
				{
					if (num2 < minSingleElbowLength)
					{
						connMSG = "两管间距不合适，不能进行连接";
						return result;
					}
					Pipe pipe2 = YJKRevitTools.NewPipe(hypiping.Piping, xyz, xyz4);
					this.SetDiameter(pipe2, diameter);
					this.ConnPipeByEblow(pipe2, hypiping.Piping);
					Pipe pipe3 = YJKRevitTools.NewPipe(hypiping.Piping, xyz4, project);
					this.SetDiameter(pipe3, diameter);
					this.SidePipeDoubleElbowConn(xyz2, otherSidePipe, pipe3, pipe2, ref connMSG);
					result = this.ConnectMainPipe(hyline, hypiping2, project, pipe3);
					this.riserPipe.Add(pipe2);
				}
			}
			else
			{
				connMSG = "两管间距不合适，不能进行连接";
			}
			return result;
		}

		private List<Pipe> ConnectMainPipe(YJKLine lineMain, YJKPiping<Pipe> hyMain, XYZ proPoint, Pipe tranPipe)
		{
			List<Pipe> list = new List<Pipe>();
			double diameter = hyMain.GetDiameter();
			if (lineMain.IsPointOnLine(proPoint) && lineMain.StartPoint.DistanceTo(proPoint) >= diameter * 1.5 && lineMain.EndPoint.DistanceTo(proPoint) >= diameter * 1.5)
			{
				this.listPipe = hyMain.Separate(proPoint);
				hyMain.Piping.Document.Regenerate();
				this.ConnPipeByTee(this.listPipe[0], this.listPipe[1], tranPipe);
				list.Add(this.listPipe[0]);
				list.Add(this.listPipe[1]);
			}
			else
			{
				this.ConnPipeByEblow(tranPipe, hyMain.Piping);
				list.Add(hyMain.Piping);
			}
			return list;
		}

		private void ConnPipeByEblow(Pipe pipe1, Pipe pipe2)
		{
			IList<Pipe> list = new List<Pipe>();
			YJKRotateFamilyInstance hyrotateFamilyInstance = new YJKRotateFamilyInstance();
			HYPipeConnect hypipeConnect = new HYPipeConnect();
			hyrotateFamilyInstance.MovePiping(pipe1);
			hyrotateFamilyInstance.MovePiping(pipe2);
			list.Add(pipe1);
			list.Add(pipe2);
			hypipeConnect.NewElbowFitting(list, true);
		}

		private void ConnPipeByTee(Pipe pipe1, Pipe pipe2, Pipe pipe3)
		{
			IList<Pipe> list = new List<Pipe>();
			YJKRotateFamilyInstance hyrotateFamilyInstance = new YJKRotateFamilyInstance();
			HYPipeConnect hypipeConnect = new HYPipeConnect();
			hyrotateFamilyInstance.MovePiping(pipe1);
			hyrotateFamilyInstance.MovePiping(pipe2);
			hyrotateFamilyInstance.MovePiping(pipe3);
			list.Add(pipe1);
			list.Add(pipe2);
			list.Add(pipe3);
			hypipeConnect.NewTeeFitting(ref list, true);
		}

		private List<Pipe> ConnParallelPipes(Pipe sidePipe, Pipe mainPipe, ref string connMSG)
		{
			YJKPiping<Pipe> hypiping = new YJKPiping<Pipe>(sidePipe);
			YJKPiping<Pipe> hypiping2 = new YJKPiping<Pipe>(mainPipe);
			List<Pipe> list = new List<Pipe>();
			Pipe piping = hypiping2.Piping;
			Document document = hypiping.Piping.Document;
			XYZ xyz = hypiping.StartConnector.Connector.IsConnected ? hypiping.EndConnector.Origin : hypiping.StartConnector.Origin;
			double diameter = hypiping.GetDiameter();
			double diameter2 = hypiping2.GetDiameter();
			YJKLine hyline = new YJKLine(hypiping2.StartConnector.Origin, hypiping2.EndConnector.Origin);
			hyline.MakeUnBound();
			XYZ project = hyline.GetProject(xyz);
			XYZ xyz2 = new XYZ(project.X, project.Y, xyz.Z);
			double num = project.DistanceTo(xyz2);
			IList<Pipe> list2 = new List<Pipe>();
			YJKRotateFamilyInstance hyrotateFamilyInstance = new YJKRotateFamilyInstance();
			HYPipeConnect hypipeConnect = new HYPipeConnect();
			if (num <= 0.016404199475065617)
			{
				Pipe pipe = YJKRevitTools.NewPipe(hypiping.Piping, xyz, project);
				this.SetDiameter(pipe, diameter);
				list2.Add(pipe);
				list2.Add(hypiping.Piping);
				hypipeConnect.NewElbowFitting(list2, true);
				if (hyline.IsPointOnLine(project) && hyline.StartPoint.DistanceTo(project) >= diameter2 * 1.5 && hyline.EndPoint.DistanceTo(project) >= diameter2 * 1.5)
				{
					List<Pipe> list3 = hypiping2.Separate(project);
					hyrotateFamilyInstance.MovePiping(list3[0]);
					hyrotateFamilyInstance.MovePiping(list3[1]);
					hyrotateFamilyInstance.MovePiping(pipe);
					document.Regenerate();
					list2 = new List<Pipe>();
					list2.Add(list3[0]);
					list2.Add(list3[1]);
					list2.Add(pipe);
					hypipeConnect.NewTeeFitting(ref list2, true);
					list.Add(list3[0]);
					list.Add(list3[1]);
				}
				else
				{
					list2 = new List<Pipe>();
					list2.Add(hypiping2.Piping);
					list2.Add(pipe);
					hypipeConnect.NewElbowFitting(list2, true);
					list.Add(hypiping2.Piping);
				}
			}
			else if (num >= (diameter + diameter2) * 1.5)
			{
				Pipe pipe2 = YJKRevitTools.NewPipe(hypiping.Piping, xyz, xyz2);
				this.SetDiameter(pipe2, diameter);
				list2.Add(pipe2);
				list2.Add(hypiping.Piping);
				hypipeConnect.NewElbowFitting(list2, true);
				Pipe pipe3 = YJKRevitTools.NewPipe(hypiping.Piping, xyz2, project);
				this.SetDiameter(pipe3, diameter);
				list2 = new List<Pipe>();
				list2.Add(pipe2);
				list2.Add(pipe3);
				hyrotateFamilyInstance.MovePiping(pipe3);
				hypipeConnect.NewElbowFitting(list2, true);
				if (hyline.IsPointOnLine(project) && hyline.StartPoint.DistanceTo(project) >= diameter2 * 1.5 && hyline.EndPoint.DistanceTo(project) >= diameter2 * 1.5)
				{
					List<Pipe> list3 = hypiping2.Separate(project);
					hyrotateFamilyInstance.MovePiping(list3[0]);
					hyrotateFamilyInstance.MovePiping(list3[1]);
					hyrotateFamilyInstance.MovePiping(pipe3);
					document.Regenerate();
					list2 = new List<Pipe>();
					list2.Add(list3[0]);
					list2.Add(list3[1]);
					list2.Add(pipe3);
					hypipeConnect.NewTeeFitting(ref list2, true);
					list.Add(list3[0]);
					list.Add(list3[1]);
				}
				else
				{
					list2 = new List<Pipe>();
					list2.Add(hypiping2.Piping);
					list2.Add(pipe3);
					hypipeConnect.NewElbowFitting(list2, true);
					list.Add(hypiping2.Piping);
				}
			}
			else
			{
				connMSG = "两管间距不合适，不能进行连接";
			}
			return list;
		}

		private List<Pipe> ConnectParallelPipes(Pipe sidePipe, Pipe mainPipe, XYZ basePnt, int styleNum, ref string connMSG, Pipe otherSidePipe)
		{
			YJKPiping<Pipe> hypiping = new YJKPiping<Pipe>(sidePipe);
			YJKPiping<Pipe> hypiping2 = new YJKPiping<Pipe>(mainPipe);
			YJKLine hyline = new YJKLine(hypiping2.StartConnector.Origin, hypiping2.EndConnector.Origin);
			List<Pipe> result = new List<Pipe>();
			Document document = mainPipe.Document;
			XYZ xyz = hypiping.StartConnector.Connector.IsConnected ? hypiping.EndConnector.Origin : hypiping.StartConnector.Origin;
			double diameter = hypiping.GetDiameter();
			double diameter2 = hypiping2.GetDiameter();
			hyline.MakeUnBound();
			XYZ project = hyline.GetProject(xyz);
			XYZ xyz2 = new XYZ(xyz.X, xyz.Y, project.Z);
			double num = xyz.DistanceTo(xyz2);
			double num2 = xyz2.DistanceTo(project);
			double num3 = 0.016404199475065617;
			double num4 = (diameter + diameter2) * 2.0;
			if (num <= num3)
			{
				if (num2 < num4)
				{
					connMSG = "两管间距不合适，不能进行连接";
					return result;
				}
				Pipe pipe = YJKRevitTools.NewPipe(hypiping.Piping, xyz, project);
				this.SetDiameter(pipe, diameter);
				this.ConnPipeByEblow(pipe, hypiping.Piping);
				result = this.ConnectMainPipe(hyline, hypiping2, project, pipe, basePnt, styleNum);
			}
			else if (num >= num4)
			{
				if (num2 <= num3)
				{
					this.MovePipe(ref xyz2, ref project, xyz, mainPipe);
					hypiping2 = new YJKPiping<Pipe>(mainPipe);
					hyline = new YJKLine(hypiping2.StartConnector.Origin, hypiping2.EndConnector.Origin);
					Pipe pipe2 = YJKRevitTools.NewPipe(hypiping.Piping, xyz, project);
					this.SetDiameter(pipe2, diameter);
					this.ConnPipeByEblow(pipe2, hypiping.Piping);
					result = this.ConnectMainPipe(hyline, hypiping2, project, pipe2, basePnt, styleNum);
					this.riserPipe.Add(pipe2);
				}
				else
				{
					if (num2 < num4)
					{
						connMSG = "两管间距不合适，不能进行连接";
						return result;
					}
					Pipe pipe = YJKRevitTools.NewPipe(hypiping.Piping, xyz, xyz2);
					this.SetDiameter(pipe, diameter);
					this.ConnPipeByEblow(pipe, hypiping.Piping);
					Pipe pipe2 = YJKRevitTools.NewPipe(hypiping.Piping, xyz2, project);
					this.SetDiameter(pipe2, diameter);
					this.SidePipeDoubleElbowConn(xyz2, otherSidePipe, pipe2, pipe, ref connMSG);
					result = this.ConnectMainPipe(hyline, hypiping2, project, pipe2, basePnt, styleNum);
					this.riserPipe.Add(pipe);
				}
			}
			else
			{
				connMSG = "两管间距不合适，不能进行连接";
			}
			return result;
		}

		private List<Pipe> ConnectMainPipe(YJKLine lineMain, YJKPiping<Pipe> hyMain, XYZ proPoint, Pipe tranPipe, XYZ basePnt, int styleNum)
		{
			List<Pipe> list = new List<Pipe>();
			double diameter = hyMain.GetDiameter();
			if (lineMain.IsPointOnLine(proPoint) && lineMain.StartPoint.DistanceTo(proPoint) >= diameter * 1.5 && lineMain.EndPoint.DistanceTo(proPoint) >= diameter * 1.5)
			{
				this.listPipe = hyMain.Separate(proPoint);
				hyMain.Piping.Document.Regenerate();
				Pipe pipeToPoint = this.GetPipeToPoint(this.listPipe, basePnt, styleNum);
				this.ConnPipeByEblow(pipeToPoint, tranPipe);
				list.Add(this.listPipe[0]);
				list.Add(this.listPipe[1]);
			}
			return list;
		}

		private List<Pipe> ConnParallelPipes(Pipe sidePipe, Pipe mainPipe, XYZ basePnt, int styleNum, ref string connMSG)
		{
			YJKPiping<Pipe> hypiping = new YJKPiping<Pipe>(sidePipe);
			YJKPiping<Pipe> hypiping2 = new YJKPiping<Pipe>(mainPipe);
			List<Pipe> list = new List<Pipe>();
			Pipe piping = hypiping2.Piping;
			Document document = hypiping.Piping.Document;
			XYZ xyz = hypiping.StartConnector.Connector.IsConnected ? hypiping.EndConnector.Origin : hypiping.StartConnector.Origin;
			double diameter = hypiping.GetDiameter();
			double diameter2 = hypiping2.GetDiameter();
			YJKLine hyline = new YJKLine(hypiping2.StartConnector.Origin, hypiping2.EndConnector.Origin);
			hyline.MakeUnBound();
			XYZ project = hyline.GetProject(xyz);
			XYZ xyz2 = new XYZ(project.X, project.Y, xyz.Z);
			double num = project.DistanceTo(xyz2);
			IList<Pipe> list2 = new List<Pipe>();
			YJKRotateFamilyInstance hyrotateFamilyInstance = new YJKRotateFamilyInstance();
			HYPipeConnect hypipeConnect = new HYPipeConnect();
			if (num <= 0.016404199475065617)
			{
				Pipe pipe = YJKRevitTools.NewPipe(hypiping.Piping, xyz, project);
				this.SetDiameter(pipe, diameter);
				list2.Add(pipe);
				list2.Add(hypiping.Piping);
				hypipeConnect.NewElbowFitting(list2, true);
				if (hyline.IsPointOnLine(project) && hyline.StartPoint.DistanceTo(project) >= diameter2 * 1.5 && hyline.EndPoint.DistanceTo(project) >= diameter2 * 1.5)
				{
					List<Pipe> list3 = hypiping2.Separate(project);
					hyrotateFamilyInstance.MovePiping(list3[0]);
					hyrotateFamilyInstance.MovePiping(list3[1]);
					hyrotateFamilyInstance.MovePiping(pipe);
					document.Regenerate();
					hypipeConnect.NewElbowFitting(new List<Pipe>
					{
						this.GetPipeToPoint(list3, basePnt, styleNum),
						pipe
					}, true);
					list.Add(list3[0]);
					list.Add(list3[1]);
				}
			}
			else if (num >= (diameter + diameter2) * 1.5)
			{
				Pipe pipe2 = YJKRevitTools.NewPipe(hypiping.Piping, xyz, xyz2);
				this.SetDiameter(pipe2, diameter);
				list2.Add(pipe2);
				list2.Add(hypiping.Piping);
				hypipeConnect.NewElbowFitting(list2, true);
				Pipe pipe3 = YJKRevitTools.NewPipe(hypiping.Piping, xyz2, project);
				this.SetDiameter(pipe3, diameter);
				list2 = new List<Pipe>();
				list2.Add(pipe2);
				list2.Add(pipe3);
				hyrotateFamilyInstance.MovePiping(pipe3);
				hypipeConnect.NewElbowFitting(list2, true);
				if (hyline.IsPointOnLine(project) && hyline.StartPoint.DistanceTo(project) >= diameter2 * 1.5 && hyline.EndPoint.DistanceTo(project) >= diameter2 * 1.5)
				{
					List<Pipe> list3 = hypiping2.Separate(project);
					hyrotateFamilyInstance.MovePiping(list3[0]);
					hyrotateFamilyInstance.MovePiping(list3[1]);
					hyrotateFamilyInstance.MovePiping(pipe3);
					document.Regenerate();
					hypipeConnect.NewElbowFitting(new List<Pipe>
					{
						this.GetPipeToPoint(list3, basePnt, styleNum),
						pipe3
					}, true);
					list.Add(list3[0]);
					list.Add(list3[1]);
				}
			}
			else
			{
				connMSG = "两管间距不合适，不能进行连接";
			}
			return list;
		}

		private List<Pipe> ConnInterSectionPipes(Pipe side, Pipe main, XYZ basePnt, int styleNum, ref string connMSG)
		{
			YJKPiping<Pipe> hypiping = new YJKPiping<Pipe>(side);
			YJKPiping<Pipe> hypiping2 = new YJKPiping<Pipe>(main);
			List<Pipe> list = new List<Pipe>();
			Document document = side.Document;
			double diameter = hypiping.GetDiameter();
			double diameter2 = hypiping2.GetDiameter();
			YJKLine hyline = new YJKLine(hypiping2.StartConnector.Origin, hypiping2.EndConnector.Origin);
			hyline.MakeUnBound();
			YJKLine hyline2 = new YJKLine(hypiping.StartConnector.Origin, hypiping.EndConnector.Origin);
			XYZ closePipePoint = this.GetClosePipePoint(hypiping, hypiping2);
			XYZ project = hyline.GetProject(closePipePoint);
			XYZ xyz = new XYZ(project.X, project.Y, closePipePoint.Z);
			double num = project.DistanceTo(xyz);
			IList<Pipe> list2 = new List<Pipe>();
			YJKRotateFamilyInstance hyrotateFamilyInstance = new YJKRotateFamilyInstance();
			HYPipeConnect hypipeConnect = new HYPipeConnect();
			if (num <= 0.016404199475065617)
			{
				Pipe pipe = hypiping.Piping;
				if (!hyline2.IsPointOnCurveLine(project))
				{
					Pipe pipe2 = YJKRevitTools.NewPipe(hypiping.Piping, closePipePoint, project);
					this.SetDiameter(pipe, diameter);
					hypipeConnect.NewElbowFitting(new List<Pipe>
					{
						pipe,
						pipe2
					}, true);
					pipe = pipe2;
				}
				if (hyline.IsPointOnLine(project) && hyline.StartPoint.DistanceTo(project) >= diameter2 * 1.5 && hyline.EndPoint.DistanceTo(project) >= diameter2 * 1.5)
				{
					List<Pipe> list3 = hypiping2.Separate(project);
					hyrotateFamilyInstance.MovePiping(list3[0]);
					hyrotateFamilyInstance.MovePiping(list3[1]);
					hyrotateFamilyInstance.MovePiping(pipe);
					document.Regenerate();
					hypipeConnect.NewElbowFitting(new List<Pipe>
					{
						this.GetPipeToPoint(list3, basePnt, styleNum),
						pipe
					}, true);
					list.Add(list3[0]);
					list.Add(list3[1]);
				}
			}
			else if (num > (diameter + diameter2) * 1.5)
			{
				Pipe pipe3 = hypiping.Piping;
				if (!hyline2.IsPointOnCurveLine(xyz))
				{
					Pipe pipe4 = YJKRevitTools.NewPipe(hypiping.Piping, closePipePoint, xyz);
					this.SetDiameter(pipe3, diameter);
					hypipeConnect.NewElbowFitting(new List<Pipe>
					{
						pipe3,
						pipe4
					}, true);
					pipe3 = pipe4;
				}
				Pipe pipe5 = YJKRevitTools.NewPipe(hypiping.Piping, xyz, project);
				this.SetDiameter(pipe5, diameter);
				hyrotateFamilyInstance.MovePiping(pipe5);
				hypipeConnect.NewElbowFitting(new List<Pipe>
				{
					pipe3,
					pipe5
				}, true);
				if (hyline.IsPointOnLine(project) && hyline.StartPoint.DistanceTo(project) >= diameter2 * 1.5 && hyline.EndPoint.DistanceTo(project) >= diameter2 * 1.5)
				{
					List<Pipe> list3 = hypiping2.Separate(project);
					hyrotateFamilyInstance.MovePiping(list3[0]);
					hyrotateFamilyInstance.MovePiping(list3[1]);
					hyrotateFamilyInstance.MovePiping(pipe5);
					document.Regenerate();
					hypipeConnect.NewElbowFitting(new List<Pipe>
					{
						pipe5,
						this.GetPipeToPoint(list3, basePnt, styleNum)
					}, true);
					list.Add(list3[0]);
					list.Add(list3[1]);
				}
			}
			else
			{
				connMSG = "两管间距不合适，不能进行连接";
			}
			return list;
		}

		private List<Pipe> ConnInterSectionPipes(Pipe side, Pipe main, ref string connMSG)
		{
			YJKPiping<Pipe> hypiping = new YJKPiping<Pipe>(side);
			YJKPiping<Pipe> hypiping2 = new YJKPiping<Pipe>(main);
			List<Pipe> list = new List<Pipe>();
			Document document = side.Document;
			double diameter = hypiping.GetDiameter();
			double diameter2 = hypiping2.GetDiameter();
			YJKLine hyline = new YJKLine(hypiping2.StartConnector.Origin, hypiping2.EndConnector.Origin);
			hyline.MakeUnBound();
			YJKLine hyline2 = new YJKLine(hypiping.StartConnector.Origin, hypiping.EndConnector.Origin);
			XYZ closePipePoint = this.GetClosePipePoint(hypiping, hypiping2);
			XYZ project = hyline.GetProject(closePipePoint);
			XYZ xyz = new XYZ(project.X, project.Y, closePipePoint.Z);
			double num = project.DistanceTo(xyz);
			IList<Pipe> list2 = new List<Pipe>();
			YJKRotateFamilyInstance hyrotateFamilyInstance = new YJKRotateFamilyInstance();
			HYPipeConnect hypipeConnect = new HYPipeConnect();
			if (num <= 0.016404199475065617)
			{
				Pipe pipe = hypiping.Piping;
				if (!hyline2.IsPointOnCurveLine(project))
				{
					Pipe pipe2 = YJKRevitTools.NewPipe(hypiping.Piping, closePipePoint, project);
					this.SetDiameter(pipe, diameter);
					list2 = new List<Pipe>();
					list2.Add(pipe);
					list2.Add(pipe2);
					hypipeConnect.NewElbowFitting(list2, true);
					pipe = pipe2;
				}
				if (hyline.IsPointOnLine(project) && hyline.StartPoint.DistanceTo(project) >= diameter2 * 1.5 && hyline.EndPoint.DistanceTo(project) >= diameter2 * 1.5)
				{
					List<Pipe> list3 = hypiping2.Separate(project);
					hyrotateFamilyInstance.MovePiping(list3[0]);
					hyrotateFamilyInstance.MovePiping(list3[1]);
					hyrotateFamilyInstance.MovePiping(pipe);
					document.Regenerate();
					list2 = new List<Pipe>();
					list2.Add(list3[0]);
					list2.Add(list3[1]);
					list2.Add(pipe);
					hypipeConnect.NewTeeFitting(ref list2, true);
					list.Add(list3[0]);
					list.Add(list3[1]);
				}
				else
				{
					list2 = new List<Pipe>();
					list2.Add(hypiping2.Piping);
					list2.Add(pipe);
					hypipeConnect.NewElbowFitting(list2, true);
					list.Add(hypiping2.Piping);
				}
			}
			else if (num > (diameter + diameter2) * 1.5)
			{
				Pipe pipe3 = hypiping.Piping;
				if (!hyline2.IsPointOnCurveLine(xyz))
				{
					Pipe pipe4 = YJKRevitTools.NewPipe(hypiping.Piping, closePipePoint, xyz);
					this.SetDiameter(pipe3, diameter);
					list2 = new List<Pipe>();
					list2.Add(pipe3);
					list2.Add(pipe4);
					hypipeConnect.NewElbowFitting(list2, true);
					pipe3 = pipe4;
				}
				Pipe pipe5 = YJKRevitTools.NewPipe(hypiping.Piping, xyz, project);
				this.SetDiameter(pipe5, diameter);
				hyrotateFamilyInstance.MovePiping(pipe5);
				list2 = new List<Pipe>();
				list2.Add(pipe3);
				list2.Add(pipe5);
				hypipeConnect.NewElbowFitting(list2, true);
				if (hyline.IsPointOnLine(project) && hyline.StartPoint.DistanceTo(project) >= diameter2 * 1.5 && hyline.EndPoint.DistanceTo(project) >= diameter2 * 1.5)
				{
					List<Pipe> list3 = hypiping2.Separate(project);
					hyrotateFamilyInstance.MovePiping(list3[0]);
					hyrotateFamilyInstance.MovePiping(list3[1]);
					hyrotateFamilyInstance.MovePiping(pipe5);
					document.Regenerate();
					list2 = new List<Pipe>();
					list2.Add(list3[0]);
					list2.Add(list3[1]);
					list2.Add(pipe5);
					hypipeConnect.NewTeeFitting(ref list2, true);
					list.Add(list3[0]);
					list.Add(list3[1]);
				}
				else
				{
					list2 = new List<Pipe>();
					list2.Add(hypiping2.Piping);
					list2.Add(pipe5);
					hypipeConnect.NewElbowFitting(list2, true);
					list.Add(hypiping2.Piping);
				}
				this.riserPipe.Add(pipe5);
			}
			else
			{
				connMSG = "两管间距不合适，不能进行连接";
			}
			return list;
		}

		private void ConnectPipeByElbow(HYPipeConnect hyConnPipe, Pipe pipe1, Pipe pipe2)
		{
			hyConnPipe.NewElbowFitting(new List<Pipe>
			{
				pipe1,
				pipe2
			}, true);
			this.doc.Regenerate();
		}

		private Pipe CreatTranPipe(Pipe basePipe, XYZ startPne, XYZ pipeVector, double pipeLength)
		{
			XYZ endXYZ = startPne.Add(pipeLength * pipeVector);
			Pipe pipe = YJKRevitTools.NewPipe(basePipe, startPne, endXYZ);
			this.doc.Regenerate();
			new YJKRotateFamilyInstance().MovePiping(pipe);
			return pipe;
		}

		private List<Pipe> ConnRiserPipes(Pipe sidePipe, Pipe mainPipe, ref string connMSG, bool beUp = true)
		{
			List<Pipe> list = new List<Pipe>();
			YJKPiping<Pipe> hypiping = new YJKPiping<Pipe>(mainPipe);
			YJKPiping<Pipe> hypiping2 = new YJKPiping<Pipe>(sidePipe);
			Document document = mainPipe.Document;
			double diameter = hypiping2.GetDiameter();
			double diameter2 = hypiping.GetDiameter();
			YJKLine hyline = new YJKLine(hypiping.StartConnector.Origin, hypiping.EndConnector.Origin);
			hyline.MakeUnBound();
			YJKLine hyline2 = new YJKLine(hypiping2.StartConnector.Origin, hypiping2.EndConnector.Origin);
			hyline2.MakeUnBound();
			Connector notConnector = this.GetNotConnector(sidePipe);
			XYZ project = hyline.GetProject(notConnector.Origin);
			XYZ project2 = hyline2.GetProject(project);
			XYZ xyz = project2.Subtract(notConnector.Origin).Normalize();
			YJKRotateFamilyInstance hyrotateFamilyInstance = new YJKRotateFamilyInstance();
			HYPipeConnect hypipeConnect = new HYPipeConnect();
			IList<Pipe> list2 = new List<Pipe>();
			if (!xyz.IsAlmostEqualTo(notConnector.CoordinateSystem.BasisZ))
			{
				if (YJKMessageBox.Show("连接口方向与连接管道相反，是否继续连接", MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk) == DialogResult.No)
				{
					return list;
				}
				XYZ xyz2 = new XYZ(0.0, 0.0, 1.0);
				if (!beUp)
				{
					xyz2 = -1.0 * xyz2;
				}
				double num = hypiping2.GetDiameter() * 12.0;
				XYZ xyz3 = notConnector.Origin.Add(num * xyz2);
				Pipe pipe = this.CreatTranPipe(hypiping2.Piping, notConnector.Origin, xyz2, num);
				this.ConnectPipeByElbow(hypipeConnect, hypiping2.Piping, pipe);
				XYZ xyz4 = notConnector.CoordinateSystem.BasisZ * -1.0;
				Pipe pipe2 = this.CreatTranPipe(hypiping2.Piping, xyz3, xyz4, num);
				this.ConnectPipeByElbow(hypipeConnect, pipe2, pipe);
				hypiping2 = new YJKPiping<Pipe>(pipe2);
				project = hyline.GetProject(xyz3);
				YJKLine hyline3 = new YJKLine(xyz3, xyz3.Add(xyz4 * 2.0));
				hyline3.MakeUnBound();
				project2 = hyline3.GetProject(project);
			}
			double num2 = project2.DistanceTo(project);
			List<Pipe> list3 = new List<Pipe>();
			if (num2 <= 0.016404199475065617)
			{
				Pipe pipe3 = hypiping2.Extend(project2, this.GetConnedConnPoint(hypiping2));
				if (hyline.IsPointOnLine(project) && hyline.StartPoint.DistanceTo(project) >= diameter2 * 1.5 && hyline.EndPoint.DistanceTo(project) >= diameter2 * 1.5)
				{
					list = hypiping.Separate(project);
					hyrotateFamilyInstance.MovePiping(list[0]);
					hyrotateFamilyInstance.MovePiping(list[1]);
					hyrotateFamilyInstance.MovePiping(pipe3);
					document.Regenerate();
					list2 = new List<Pipe>();
					list2.Add(list[0]);
					list2.Add(list[1]);
					list2.Add(pipe3);
					hypipeConnect.NewTeeFitting(ref list2, true);
					list3.Add(list[0]);
					list3.Add(list[1]);
				}
				else
				{
					list2 = new List<Pipe>();
					list2.Add(hypiping.Piping);
					list2.Add(pipe3);
					hypipeConnect.NewElbowFitting2(list2);
					list3.Add(hypiping.Piping);
				}
			}
			else if (num2 > (diameter + diameter2) * 1.5)
			{
				Pipe piping = hypiping2.Piping;
				Pipe pipe4 = YJKRevitTools.NewPipe(hypiping2.Piping, project2, project);
				this.SetDiameter(pipe4, diameter);
				hyrotateFamilyInstance.MovePiping(pipe4);
				list2 = new List<Pipe>();
				list2.Add(piping);
				list2.Add(pipe4);
				hypipeConnect.NewElbowFitting(list2, true);
				if (hyline.IsPointOnLine(project) && hyline.StartPoint.DistanceTo(project) >= diameter2 * 1.5 && hyline.EndPoint.DistanceTo(project) >= diameter2 * 1.5)
				{
					list = hypiping.Separate(project);
					hyrotateFamilyInstance.MovePiping(list[0]);
					hyrotateFamilyInstance.MovePiping(list[1]);
					hyrotateFamilyInstance.MovePiping(pipe4);
					document.Regenerate();
					list2 = new List<Pipe>();
					list2.Add(list[0]);
					list2.Add(list[1]);
					list2.Add(pipe4);
					hypipeConnect.NewTeeFitting(ref list2, true);
					list3.Add(list[0]);
					list3.Add(list[1]);
				}
				else
				{
					list2 = new List<Pipe>();
					list2.Add(hypiping.Piping);
					list2.Add(pipe4);
					hypipeConnect.NewElbowFitting(list2, true);
					list3.Add(hypiping.Piping);
				}
			}
			else
			{
				connMSG = "两管间距不合适，不能进行连接";
			}
			return list;
		}

		private XYZ GetConnedConnPoint(YJKPiping<Pipe> hyPipe)
		{
			if (!hyPipe.StartConnector.Connector.IsConnected)
			{
				return hyPipe.EndConnector.Origin;
			}
			return hyPipe.StartConnector.Origin;
		}

		private List<Pipe> ConnRPipesOver1(Pipe sidePipe, Pipe mainPipe, Pipe pipe1, XYZ facingVector, ref string connMSG, bool beUp = true)
		{
			List<Pipe> list = new List<Pipe>();
			YJKPiping<Pipe> hypiping = new YJKPiping<Pipe>(mainPipe);
			YJKPiping<Pipe> hypiping2 = new YJKPiping<Pipe>(sidePipe);
			Document document = mainPipe.Document;
			double diameter = hypiping2.GetDiameter();
			double diameter2 = hypiping.GetDiameter();
			YJKLine hyline = new YJKLine(hypiping.StartConnector.Origin, hypiping.EndConnector.Origin);
			hyline.MakeUnBound();
			YJKLine hyline2 = new YJKLine(hypiping2.StartConnector.Origin, hypiping2.EndConnector.Origin);
			hyline2.MakeUnBound();
			Connector notConnector = this.GetNotConnector(sidePipe);
			XYZ project = hyline.GetProject(notConnector.Origin);
			XYZ project2 = hyline2.GetProject(project);
			XYZ xyz = project2.Subtract(notConnector.Origin).Normalize();
			YJKRotateFamilyInstance hyrotateFamilyInstance = new YJKRotateFamilyInstance();
			HYPipeConnect hypipeConnect = new HYPipeConnect();
			IList<Pipe> list2 = new List<Pipe>();
			if (!xyz.IsAlmostEqualTo(notConnector.CoordinateSystem.BasisZ))
			{
				if (YJKMessageBox.Show("连接口方向与连接管道相反，是否继续连接", MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk) == DialogResult.No)
				{
					return list;
				}
				XYZ xyz2 = new XYZ(0.0, 0.0, 1.0);
				if (!beUp)
				{
					xyz2 = -1.0 * xyz2;
				}
				double num = hypiping2.GetDiameter() * 12.0;
				XYZ xyz3 = notConnector.Origin.Add(num * xyz2);
				Pipe pipe2 = this.CreatTranPipe(hypiping2.Piping, notConnector.Origin, xyz2, num);
				this.ConnectPipeByElbow(hypipeConnect, hypiping2.Piping, pipe2);
				XYZ xyz4 = notConnector.CoordinateSystem.BasisZ * -1.0;
				Pipe pipe3 = this.CreatTranPipe(hypiping2.Piping, xyz3, xyz4, num);
				this.ConnectPipeByElbow(hypipeConnect, pipe3, pipe2);
				hypiping2 = new YJKPiping<Pipe>(pipe3);
				project = hyline.GetProject(xyz3);
				YJKLine hyline3 = new YJKLine(xyz3, xyz3.Add(xyz4 * 2.0));
				hyline3.MakeUnBound();
				project2 = hyline3.GetProject(project);
			}
			double num2 = project2.DistanceTo(project);
			List<Pipe> list3 = new List<Pipe>();
			if (num2 <= 0.016404199475065617)
			{
				Pipe pipe4 = hypiping2.Extend(project2, this.GetConnedConnPoint(hypiping2));
				if (hyline.IsPointOnLine(project) && hyline.StartPoint.DistanceTo(project) >= diameter2 * 1.5 && hyline.EndPoint.DistanceTo(project) >= diameter2 * 1.5)
				{
					list = hypiping.Separate(project);
					hyrotateFamilyInstance.MovePiping(list[0]);
					hyrotateFamilyInstance.MovePiping(list[1]);
					hyrotateFamilyInstance.MovePiping(pipe4);
					document.Regenerate();
					list2 = new List<Pipe>();
					list2.Add(list[0]);
					list2.Add(list[1]);
					list2.Add(pipe4);
					hypipeConnect.NewTeeFitting(ref list2, true);
					list3.Add(list[0]);
					list3.Add(list[1]);
				}
				else
				{
					list2 = new List<Pipe>();
					list2.Add(hypiping.Piping);
					list2.Add(pipe4);
					hypipeConnect.NewElbowFitting2(list2);
					list3.Add(hypiping.Piping);
				}
				List<Pipe> list4 = new List<Pipe>();
				hypipeConnect.NewUnionFittings(pipe4, pipe1, document, facingVector, ref connMSG, ref list4);
			}
			else if (num2 > (diameter + diameter2) * 1.5)
			{
				Pipe piping = hypiping2.Piping;
				Pipe pipe5 = YJKRevitTools.NewPipe(hypiping2.Piping, project2, project);
				this.SetDiameter(pipe5, diameter);
				hyrotateFamilyInstance.MovePiping(pipe5);
				list2 = new List<Pipe>();
				list2.Add(piping);
				list2.Add(pipe5);
				hypipeConnect.NewElbowFitting(list2, true);
				if (hyline.IsPointOnLine(project) && hyline.StartPoint.DistanceTo(project) >= diameter2 * 1.5 && hyline.EndPoint.DistanceTo(project) >= diameter2 * 1.5)
				{
					list = hypiping.Separate(project);
					hyrotateFamilyInstance.MovePiping(list[0]);
					hyrotateFamilyInstance.MovePiping(list[1]);
					hyrotateFamilyInstance.MovePiping(pipe5);
					document.Regenerate();
					list2 = new List<Pipe>();
					list2.Add(list[0]);
					list2.Add(list[1]);
					list2.Add(pipe5);
					hypipeConnect.NewTeeFitting(ref list2, true);
					list3.Add(list[0]);
					list3.Add(list[1]);
				}
				else
				{
					list2 = new List<Pipe>();
					list2.Add(hypiping.Piping);
					list2.Add(pipe5);
					hypipeConnect.NewElbowFitting(list2, true);
					list3.Add(hypiping.Piping);
				}
				List<Pipe> list5 = new List<Pipe>();
				hypipeConnect.NewUnionFittings(piping, pipe1, document, facingVector, ref connMSG, ref list5);
			}
			else
			{
				connMSG = "两管间距不合适，不能进行连接";
			}
			return list;
		}

		private List<Pipe> ConnRPipesOver2(Pipe sidePipe, Pipe mainPipe, Pipe pipe1, ref string connMSG, bool beUp = true)
		{
			List<Pipe> list = new List<Pipe>();
			YJKPiping<Pipe> hypiping = new YJKPiping<Pipe>(mainPipe);
			YJKPiping<Pipe> hypiping2 = new YJKPiping<Pipe>(sidePipe);
			Document document = mainPipe.Document;
			double diameter = hypiping2.GetDiameter();
			double diameter2 = hypiping.GetDiameter();
			YJKLine hyline = new YJKLine(hypiping.StartConnector.Origin, hypiping.EndConnector.Origin);
			hyline.MakeUnBound();
			YJKLine hyline2 = new YJKLine(hypiping2.StartConnector.Origin, hypiping2.EndConnector.Origin);
			hyline2.MakeUnBound();
			Connector notConnector = this.GetNotConnector(sidePipe);
			XYZ project = hyline.GetProject(notConnector.Origin);
			XYZ project2 = hyline2.GetProject(project);
			XYZ xyz = project2.Subtract(notConnector.Origin).Normalize();
			YJKRotateFamilyInstance hyrotateFamilyInstance = new YJKRotateFamilyInstance();
			HYPipeConnect hypipeConnect = new HYPipeConnect();
			IList<Pipe> list2 = new List<Pipe>();
			if (!xyz.IsAlmostEqualTo(notConnector.CoordinateSystem.BasisZ))
			{
				if (YJKMessageBox.Show("连接口方向与连接管道相反，是否继续连接", MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk) == DialogResult.No)
				{
					return list;
				}
				XYZ xyz2 = new XYZ(0.0, 0.0, 1.0);
				if (!beUp)
				{
					xyz2 = -1.0 * xyz2;
				}
				double num = hypiping2.GetDiameter() * 12.0;
				XYZ xyz3 = notConnector.Origin.Add(num * xyz2);
				Pipe pipe2 = this.CreatTranPipe(hypiping2.Piping, notConnector.Origin, xyz2, num);
				this.ConnectPipeByElbow(hypipeConnect, hypiping2.Piping, pipe2);
				XYZ xyz4 = notConnector.CoordinateSystem.BasisZ * -1.0;
				Pipe pipe3 = this.CreatTranPipe(hypiping2.Piping, xyz3, xyz4, num);
				this.ConnectPipeByElbow(hypipeConnect, pipe3, pipe2);
				hypiping2 = new YJKPiping<Pipe>(pipe3);
				project = hyline.GetProject(xyz3);
				YJKLine hyline3 = new YJKLine(xyz3, xyz3.Add(xyz4 * 2.0));
				hyline3.MakeUnBound();
				project2 = hyline3.GetProject(project);
			}
			double num2 = project2.DistanceTo(project);
			List<Pipe> list3 = new List<Pipe>();
			if (num2 <= 0.016404199475065617)
			{
				Pipe piping = hypiping2.Piping;
				if (hyline.IsPointOnLine(project) && hyline.StartPoint.DistanceTo(project) >= diameter2 * 1.5 && hyline.EndPoint.DistanceTo(project) >= diameter2 * 1.5)
				{
					list = hypiping.Separate(project);
					hyrotateFamilyInstance.MovePiping(list[0]);
					hyrotateFamilyInstance.MovePiping(list[1]);
					hyrotateFamilyInstance.MovePiping(piping);
					document.Regenerate();
					list2 = new List<Pipe>();
					list2.Add(list[0]);
					list2.Add(list[1]);
					list2.Add(piping);
					hypipeConnect.NewTeeFitting(ref list2, true);
					list3.Add(list[0]);
					list3.Add(list[1]);
				}
				else
				{
					list2 = new List<Pipe>();
					list2.Add(hypiping.Piping);
					list2.Add(piping);
					hypipeConnect.NewElbowFitting(list2, true);
					list3.Add(hypiping.Piping);
				}
			}
			else if (num2 > (diameter + diameter2) * 1.5)
			{
				Pipe piping2 = hypiping2.Piping;
				Pipe pipe4 = YJKRevitTools.NewPipe(hypiping2.Piping, project2, project);
				this.SetDiameter(pipe4, diameter);
				hyrotateFamilyInstance.MovePiping(pipe4);
				list2 = new List<Pipe>();
				list2.Add(piping2);
				list2.Add(pipe4);
				hypipeConnect.NewElbowFitting(list2, true);
				if (hyline.IsPointOnLine(project) && hyline.StartPoint.DistanceTo(project) >= diameter2 * 1.5 && hyline.EndPoint.DistanceTo(project) >= diameter2 * 1.5)
				{
					list = hypiping.Separate(project);
					hyrotateFamilyInstance.MovePiping(list[0]);
					hyrotateFamilyInstance.MovePiping(list[1]);
					hyrotateFamilyInstance.MovePiping(pipe4);
					document.Regenerate();
					list2 = new List<Pipe>();
					list2.Add(list[0]);
					list2.Add(list[1]);
					list2.Add(pipe4);
					hypipeConnect.NewTeeFitting(ref list2, true);
					list3.Add(list[0]);
					list3.Add(list[1]);
				}
				else
				{
					list2 = new List<Pipe>();
					list2.Add(hypiping.Piping);
					list2.Add(pipe4);
					hypipeConnect.NewElbowFitting(list2, true);
					list3.Add(hypiping.Piping);
				}
				List<Pipe> list4 = new List<Pipe>();
				hypipeConnect.NewUnionFittings(pipe4, pipe1, document, xyz, ref connMSG, ref list4);
			}
			else
			{
				connMSG = "两管间距不合适，不能进行连接";
			}
			return list;
		}

		private List<Pipe> ConnRPipesSingleElbow(Pipe sidePipe, Pipe mainPipe, Pipe pipe1, ref string connMSG, bool beUp = true)
		{
			List<Pipe> list = new List<Pipe>();
			YJKPiping<Pipe> hypiping = new YJKPiping<Pipe>(mainPipe);
			YJKPiping<Pipe> hypiping2 = new YJKPiping<Pipe>(sidePipe);
			YJKPiping<Pipe> hypiping3 = new YJKPiping<Pipe>(pipe1);
			Document document = mainPipe.Document;
			double diameter = hypiping2.GetDiameter();
			double diameter2 = hypiping.GetDiameter();
			double rAvoidMainPipe = hypiping2.GetOuterDiameter() / 2.0;
			double rBranchPipe = hypiping3.GetOuterDiameter() / 2.0;
			YJKLine hyline = new YJKLine(hypiping.StartConnector.Origin, hypiping.EndConnector.Origin);
			hyline.MakeUnBound();
			YJKLine hyline2 = new YJKLine(hypiping2.StartConnector.Origin, hypiping2.EndConnector.Origin);
			hyline2.MakeUnBound();
			Connector notConnector = this.GetNotConnector(sidePipe);
			XYZ project = hyline.GetProject(notConnector.Origin);
			XYZ project2 = hyline2.GetProject(project);
			XYZ xyz = project2.Subtract(notConnector.Origin).Normalize();
			YJKRotateFamilyInstance hyrotateFamilyInstance = new YJKRotateFamilyInstance();
			HYPipeConnect hypipeConnect = new HYPipeConnect();
			IList<Pipe> list2 = new List<Pipe>();
			if (!xyz.IsAlmostEqualTo(notConnector.CoordinateSystem.BasisZ))
			{
				if (YJKMessageBox.Show("连接口方向与连接管道相反，是否继续连接", MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk) == DialogResult.No)
				{
					return list;
				}
				XYZ xyz2 = new XYZ(0.0, 0.0, 1.0);
				if (!beUp)
				{
					xyz2 = -1.0 * xyz2;
				}
				double num = hypiping2.GetDiameter() * 12.0;
				XYZ xyz3 = notConnector.Origin.Add(num * xyz2);
				Pipe pipe2 = this.CreatTranPipe(hypiping2.Piping, notConnector.Origin, xyz2, num);
				this.ConnectPipeByElbow(hypipeConnect, hypiping2.Piping, pipe2);
				XYZ xyz4 = notConnector.CoordinateSystem.BasisZ * -1.0;
				Pipe pipe3 = this.CreatTranPipe(hypiping2.Piping, xyz3, xyz4, num);
				this.ConnectPipeByElbow(hypipeConnect, pipe3, pipe2);
				hypiping2 = new YJKPiping<Pipe>(pipe3);
				project = hyline.GetProject(xyz3);
				YJKLine hyline3 = new YJKLine(xyz3, xyz3.Add(xyz4 * 2.0));
				hyline3.MakeUnBound();
				project2 = hyline3.GetProject(project);
			}
			double num2 = project2.DistanceTo(project);
			List<Pipe> list3 = new List<Pipe>();
			if (num2 <= 0.016404199475065617)
			{
				Pipe piping = hypiping2.Piping;
				if (hyline.IsPointOnLine(project) && hyline.StartPoint.DistanceTo(project) >= diameter2 * 1.5 && hyline.EndPoint.DistanceTo(project) >= diameter2 * 1.5)
				{
					list = hypiping.Separate(project);
					hyrotateFamilyInstance.MovePiping(list[0]);
					hyrotateFamilyInstance.MovePiping(list[1]);
					hyrotateFamilyInstance.MovePiping(piping);
					document.Regenerate();
					list2 = new List<Pipe>();
					list2.Add(list[0]);
					list2.Add(list[1]);
					list2.Add(piping);
					hypipeConnect.NewTeeFitting(ref list2, true);
					list3.Add(list[0]);
					list3.Add(list[1]);
				}
				else
				{
					list2 = new List<Pipe>();
					list2.Add(hypiping.Piping);
					list2.Add(piping);
					hypipeConnect.NewElbowFitting(list2, true);
					list3.Add(hypiping.Piping);
				}
			}
			else if (num2 > RadiatorConnHelper.GetMinSingleElbowLength(rAvoidMainPipe, rBranchPipe))
			{
				XYZ startXYZ = project2.Add(-xyz.Normalize() * project.DistanceTo(project2));
				Pipe piping2 = hypiping2.Piping;
				Pipe pipe4 = YJKRevitTools.NewPipe(hypiping2.Piping, startXYZ, project);
				this.SetDiameter(pipe4, diameter);
				hyrotateFamilyInstance.MovePiping(pipe4);
				list2 = new List<Pipe>();
				list2.Add(piping2);
				list2.Add(pipe4);
				hypipeConnect.NewElbowFitting(list2, true);
				if (hyline.IsPointOnLine(project) && hyline.StartPoint.DistanceTo(project) >= diameter2 * 1.5 && hyline.EndPoint.DistanceTo(project) >= diameter2 * 1.5)
				{
					list = hypiping.Separate(project);
					hyrotateFamilyInstance.MovePiping(list[0]);
					hyrotateFamilyInstance.MovePiping(list[1]);
					hyrotateFamilyInstance.MovePiping(pipe4);
					document.Regenerate();
					list2 = new List<Pipe>();
					list2.Add(list[0]);
					list2.Add(list[1]);
					list2.Add(pipe4);
					hypipeConnect.NewTeeFitting(ref list2, true);
					list3.Add(list[0]);
					list3.Add(list[1]);
				}
				else
				{
					list2 = new List<Pipe>();
					list2.Add(hypiping.Piping);
					list2.Add(pipe4);
					hypipeConnect.NewElbowFitting(list2, true);
					list3.Add(hypiping.Piping);
				}
			}
			else
			{
				connMSG = "两管间距不合适，不能进行连接";
			}
			return list;
		}

		private List<Pipe> ConnRPipesDoubleElbow(Pipe sidePipe, Pipe mainPipe, Pipe pipe1, ref string connMSG, bool beUp = true)
		{
			List<Pipe> list = new List<Pipe>();
			YJKPiping<Pipe> hypiping = new YJKPiping<Pipe>(mainPipe);
			YJKPiping<Pipe> hypiping2 = new YJKPiping<Pipe>(sidePipe);
			YJKPiping<Pipe> hypiping3 = new YJKPiping<Pipe>(pipe1);
			Document document = mainPipe.Document;
			double diameter = hypiping2.GetDiameter();
			double diameter2 = hypiping.GetDiameter();
			double rBranchPipe = hypiping2.GetOuterDiameter() / 2.0;
			double rConnMainPipe = hypiping.GetOuterDiameter() / 2.0;
			double rAvoidMainPipe = hypiping3.GetOuterDiameter() / 2.0;
			YJKLine hyline = new YJKLine(hypiping.StartConnector.Origin, hypiping.EndConnector.Origin);
			hyline.MakeUnBound();
			YJKLine hyline2 = new YJKLine(hypiping2.StartConnector.Origin, hypiping2.EndConnector.Origin);
			hyline2.MakeUnBound();
			Connector notConnector = this.GetNotConnector(sidePipe);
			XYZ project = hyline.GetProject(notConnector.Origin);
			XYZ project2 = hyline2.GetProject(project);
			XYZ xyz = project2.Subtract(notConnector.Origin).Normalize();
			YJKRotateFamilyInstance hyrotateFamilyInstance = new YJKRotateFamilyInstance();
			HYPipeConnect hypipeConnect = new HYPipeConnect();
			IList<Pipe> list2 = new List<Pipe>();
			if (!xyz.IsAlmostEqualTo(notConnector.CoordinateSystem.BasisZ))
			{
				if (YJKMessageBox.Show("连接口方向与连接管道相反，是否继续连接", MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk) == DialogResult.No)
				{
					return list;
				}
				XYZ xyz2 = new XYZ(0.0, 0.0, 1.0);
				if (!beUp)
				{
					xyz2 = -1.0 * xyz2;
				}
				double num = hypiping2.GetDiameter() * 12.0;
				XYZ xyz3 = notConnector.Origin.Add(num * xyz2);
				Pipe pipe2 = this.CreatTranPipe(hypiping2.Piping, notConnector.Origin, xyz2, num);
				this.ConnectPipeByElbow(hypipeConnect, hypiping2.Piping, pipe2);
				XYZ xyz4 = notConnector.CoordinateSystem.BasisZ * -1.0;
				Pipe pipe3 = this.CreatTranPipe(hypiping2.Piping, xyz3, xyz4, num);
				this.ConnectPipeByElbow(hypipeConnect, pipe3, pipe2);
				hypiping2 = new YJKPiping<Pipe>(pipe3);
				project = hyline.GetProject(xyz3);
				YJKLine hyline3 = new YJKLine(xyz3, xyz3.Add(xyz4 * 2.0));
				hyline3.MakeUnBound();
				project2 = hyline3.GetProject(project);
			}
			double num2 = project2.DistanceTo(project);
			List<Pipe> list3 = new List<Pipe>();
			if (num2 <= 0.016404199475065617)
			{
				Pipe piping = hypiping2.Piping;
				if (hyline.IsPointOnLine(project) && hyline.StartPoint.DistanceTo(project) >= diameter2 * 1.5 && hyline.EndPoint.DistanceTo(project) >= diameter2 * 1.5)
				{
					list = hypiping.Separate(project);
					hyrotateFamilyInstance.MovePiping(list[0]);
					hyrotateFamilyInstance.MovePiping(list[1]);
					hyrotateFamilyInstance.MovePiping(piping);
					document.Regenerate();
					list2 = new List<Pipe>();
					list2.Add(list[0]);
					list2.Add(list[1]);
					list2.Add(piping);
					hypipeConnect.NewTeeFitting(ref list2, true);
					list3.Add(list[0]);
					list3.Add(list[1]);
				}
				else
				{
					list2 = new List<Pipe>();
					list2.Add(hypiping.Piping);
					list2.Add(piping);
					hypipeConnect.NewElbowFitting(list2, true);
					list3.Add(hypiping.Piping);
				}
			}
			else if (num2 > RadiatorConnHelper.GetMinDoubleElbowLength(rAvoidMainPipe, rConnMainPipe, rBranchPipe))
			{
				Pipe piping2 = hypiping2.Piping;
				Pipe pipe4 = YJKRevitTools.NewPipe(hypiping2.Piping, project2, project);
				this.SetDiameter(pipe4, diameter);
				hyrotateFamilyInstance.MovePiping(pipe4);
				list2 = new List<Pipe>();
				list2.Add(piping2);
				list2.Add(pipe4);
				hypipeConnect.NewElbowConnect(piping2, pipe4, pipe1, document, ref connMSG);
				if (hyline.IsPointOnLine(project) && hyline.StartPoint.DistanceTo(project) >= diameter2 * 1.5 && hyline.EndPoint.DistanceTo(project) >= diameter2 * 1.5)
				{
					list = hypiping.Separate(project);
					hyrotateFamilyInstance.MovePiping(list[0]);
					hyrotateFamilyInstance.MovePiping(list[1]);
					hyrotateFamilyInstance.MovePiping(pipe4);
					document.Regenerate();
					list2 = new List<Pipe>();
					list2.Add(list[0]);
					list2.Add(list[1]);
					list2.Add(pipe4);
					hypipeConnect.NewTeeFitting(ref list2, true);
					list3.Add(list[0]);
					list3.Add(list[1]);
				}
				else
				{
					list2 = new List<Pipe>();
					list2.Add(hypiping.Piping);
					list2.Add(pipe4);
					hypipeConnect.NewElbowFitting(list2, true);
					list3.Add(hypiping.Piping);
				}
			}
			else
			{
				connMSG = "两管间距不合适，不能进行连接";
			}
			return list;
		}

		private List<Pipe> ConnRiserPipes(Pipe sidePipe, Pipe mainPipe, int styleNum, ref string connMSG, bool beUp)
		{
			List<Pipe> list = new List<Pipe>();
			YJKPiping<Pipe> hypiping = new YJKPiping<Pipe>(mainPipe);
			YJKPiping<Pipe> hypiping2 = new YJKPiping<Pipe>(sidePipe);
			Document document = mainPipe.Document;
			double diameter = hypiping2.GetDiameter();
			double diameter2 = hypiping.GetDiameter();
			YJKLine hyline = new YJKLine(hypiping.StartConnector.Origin, hypiping.EndConnector.Origin);
			hyline.MakeUnBound();
			YJKLine hyline2 = new YJKLine(hypiping2.StartConnector.Origin, hypiping2.EndConnector.Origin);
			hyline2.MakeUnBound();
			Connector notConnector = this.GetNotConnector(sidePipe);
			XYZ project = hyline.GetProject(notConnector.Origin);
			XYZ project2 = hyline2.GetProject(project);
			XYZ xyz = project2.Subtract(notConnector.Origin).Normalize();
			HYPipeConnect hypipeConnect = new HYPipeConnect();
			if (!xyz.IsAlmostEqualTo(notConnector.CoordinateSystem.BasisZ))
			{
				connMSG = "连接口方向与连接管道相反，是否继续连接";
				if (YJKMessageBox.Show(connMSG, MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk) == DialogResult.No)
				{
					return list;
				}
				XYZ xyz2 = new XYZ(0.0, 0.0, 1.0);
				if (!beUp)
				{
					xyz2 = -1.0 * xyz2;
				}
				double num = hypiping2.GetDiameter() * 12.0;
				XYZ xyz3 = notConnector.Origin.Add(num * xyz2);
				Pipe pipe = this.CreatTranPipe(hypiping2.Piping, notConnector.Origin, xyz2, num);
				this.ConnectPipeByElbow(hypipeConnect, hypiping2.Piping, pipe);
				XYZ xyz4 = notConnector.CoordinateSystem.BasisZ * -1.0;
				Pipe pipe2 = this.CreatTranPipe(hypiping2.Piping, xyz3, xyz4, num);
				this.ConnectPipeByElbow(hypipeConnect, pipe2, pipe);
				hypiping2 = new YJKPiping<Pipe>(pipe2);
				project = hyline.GetProject(xyz3);
				YJKLine hyline3 = new YJKLine(xyz3, xyz3.Add(xyz4 * 2.0));
				hyline3.MakeUnBound();
				project2 = hyline3.GetProject(project);
			}
			double num2 = project2.DistanceTo(project);
			YJKRotateFamilyInstance hyrotateFamilyInstance = new YJKRotateFamilyInstance();
			IList<Pipe> list2 = new List<Pipe>();
			List<Pipe> list3 = new List<Pipe>();
			if (num2 <= 0.016404199475065617)
			{
				Pipe piping = hypiping2.Piping;
				if (hyline.IsPointOnLine(project) && hyline.StartPoint.DistanceTo(project) >= diameter2 * 1.5 && hyline.EndPoint.DistanceTo(project) >= diameter2 * 1.5)
				{
					list = hypiping.Separate(project);
					hyrotateFamilyInstance.MovePiping(list[0]);
					hyrotateFamilyInstance.MovePiping(list[1]);
					hyrotateFamilyInstance.MovePiping(piping);
					document.Regenerate();
					hypipeConnect.NewElbowFitting(new List<Pipe>
					{
						this.GetPipeByOffset(list, styleNum),
						piping
					}, true);
					list3.Add(list[0]);
					list3.Add(list[1]);
				}
			}
			else if (num2 > (diameter + diameter2) * 1.5)
			{
				Pipe piping2 = hypiping2.Piping;
				Pipe pipe3 = YJKRevitTools.NewPipe(hypiping2.Piping, project2, project);
				this.SetDiameter(pipe3, diameter);
				hyrotateFamilyInstance.MovePiping(pipe3);
				hypipeConnect.NewElbowFitting(new List<Pipe>
				{
					piping2,
					pipe3
				}, true);
				if (hyline.IsPointOnLine(project) && hyline.StartPoint.DistanceTo(project) >= diameter2 * 1.5 && hyline.EndPoint.DistanceTo(project) >= diameter2 * 1.5)
				{
					list = hypiping.Separate(project);
					hyrotateFamilyInstance.MovePiping(list[0]);
					hyrotateFamilyInstance.MovePiping(list[1]);
					hyrotateFamilyInstance.MovePiping(pipe3);
					document.Regenerate();
					hypipeConnect.NewElbowFitting(new List<Pipe>
					{
						this.GetPipeByOffset(list, styleNum),
						pipe3
					}, true);
					list3.Add(list[0]);
					list3.Add(list[1]);
				}
			}
			else
			{
				connMSG = "两管间距不合适，不能进行连接";
			}
			return list;
		}

		private Connector GetNotConnector(Pipe pipe)
		{
			Connector result = null;
			YJKPiping<Pipe> hypiping = new YJKPiping<Pipe>(pipe);
			if (!hypiping.StartConnector.Connector.IsConnected)
			{
				result = hypiping.StartConnector.Connector;
			}
			if (!hypiping.EndConnector.Connector.IsConnected)
			{
				result = hypiping.EndConnector.Connector;
			}
			return result;
		}

		private Pipe GetFarPipeToPoint(IList<Pipe> listPipe, XYZ point)
		{
			Pipe result = null;
			double num = 0.0;
			foreach (Pipe pipe in listPipe)
			{
				YJKPiping<Pipe> hypiping = new YJKPiping<Pipe>(pipe);
				XYZ xyz = hypiping.StartConnector.Origin.Add(hypiping.EndConnector.Origin) / 2.0;
				if (xyz.DistanceTo(point) > num)
				{
					num = xyz.DistanceTo(point);
					result = pipe;
				}
			}
			return result;
		}

		private Pipe GetPipeByOffset(IList<Pipe> listPipe, int styleNum)
		{
			Pipe result = null;
			if (listPipe.Count != 2)
			{
				return result;
			}
			YJKPiping<Pipe> hypiping = new YJKPiping<Pipe>(listPipe[0]);
			YJKPiping<Pipe> hypiping2 = new YJKPiping<Pipe>(listPipe[1]);
			XYZ xyz = hypiping.StartConnector.Origin.Add(hypiping.EndConnector.Origin) / 2.0;
			XYZ xyz2 = hypiping2.StartConnector.Origin.Add(hypiping2.EndConnector.Origin) / 2.0;
			if (styleNum == 1)
			{
				if (xyz.Z > xyz2.Z)
				{
					result = listPipe[0];
				}
				else
				{
					result = listPipe[1];
				}
			}
			if (styleNum == 2)
			{
				if (xyz.Z > xyz2.Z)
				{
					result = listPipe[1];
				}
				else
				{
					result = listPipe[0];
				}
			}
			return result;
		}

		private Pipe GetPipeToPoint(IList<Pipe> listPipe, XYZ point, int styleNum)
		{
			Pipe result = null;
			double num = 0.0;
			for (int i = 0; i < listPipe.Count; i++)
			{
				YJKPiping<Pipe> hypiping = new YJKPiping<Pipe>(listPipe[i]);
				XYZ xyz = hypiping.StartConnector.Origin.Add(hypiping.EndConnector.Origin) / 2.0;
				if (i == 0)
				{
					num = xyz.DistanceTo(point);
				}
				if (styleNum == 1 && xyz.DistanceTo(point) >= num)
				{
					num = xyz.DistanceTo(point);
					result = listPipe[i];
				}
				if (styleNum == 2 && xyz.DistanceTo(point) <= num)
				{
					num = xyz.DistanceTo(point);
					result = listPipe[i];
				}
			}
			return result;
		}

		private XYZ GetClosePipePoint(YJKPiping<Pipe> hySide, YJKPiping<Pipe> hyMain)
		{
			YJKLine hyline = new YJKLine(hySide.StartConnector.Origin, hySide.EndConnector.Origin);
			YJKLine hyline2 = new YJKLine(hyMain.StartConnector.Origin, hyMain.EndConnector.Origin);
			hyline2.MakeUnBound();
			if (hyline2.GetDistance(hyline.EndPoint) <= hyline2.GetDistance(hyline.StartPoint))
			{
				return hyline.EndPoint;
			}
			return hyline.StartPoint;
		}

		private List<RadiatorConnParam> OrderByRadiatorSingle(List<RadiatorConnParam> radiatorSet, ref XYZ basePnt)
		{
			List<RadiatorConnParam> list = new List<RadiatorConnParam>();
			if (!this.ChangePipeLine(ref radiatorSet, 1, ref basePnt))
			{
				YJKMessageBox.Warning("连接用管道不能为空。");
				return list;
			}
			this.Doc.Regenerate();
			if (!this.ChangePipeLine(ref radiatorSet, 2, ref basePnt))
			{
				YJKMessageBox.Warning("连接用管道不能为空。");
				return list;
			}
			this.Doc.Regenerate();
			if (this.SupplyPipe == null)
			{
				YJKMessageBox.Warning("连接用管道不能为空。");
				return list;
			}
			YJKPiping<Pipe> hypiping = new YJKPiping<Pipe>(this.SupplyPipe);
			XYZ origin = hypiping.StartConnector.Origin;
			XYZ origin2 = hypiping.EndConnector.Origin;
			XYZ xyz = origin.Subtract(origin2).Normalize();
			basePnt = ((origin.DistanceTo(basePnt) > origin2.DistanceTo(basePnt)) ? origin2 : origin);
			double num = 0.0001;
			foreach (RadiatorConnParam radiatorConnParam in radiatorSet)
			{
				double distanceOfEnd = radiatorConnParam.InExPipeConn.Origin.DistanceTo(basePnt);
				radiatorConnParam.DistanceOfEnd = distanceOfEnd;
				XYZ basisZ = radiatorConnParam.InConnector.CoordinateSystem.BasisZ;
				XYZ direction = xyz.CrossProduct(basisZ);
				double twoVectorAngle = YJKRevitTools.GetTwoVectorAngle(xyz, basisZ, direction);
				if (twoVectorAngle <= num || Math.Abs(twoVectorAngle - Math.PI) <= num || Math.Abs(twoVectorAngle - Math.PI*2) < num)
				{
					radiatorConnParam.ReDirection = 0;
				}
				else if (Math.Abs(twoVectorAngle - Math.PI*.5) <= num || Math.Abs(twoVectorAngle - 4.71238898038469) <= num)
				{
					radiatorConnParam.ReDirection = 1;
				}
				else
				{
					radiatorConnParam.ReDirection = 2;
				}
			}
			list = (from c in radiatorSet
			orderby c.DistanceOfEnd
			select c).ToList<RadiatorConnParam>();
			int num2 = 1;
			for (int i = 0; i < list.Count; i++)
			{
				if (i == 0)
				{
					list[i].IndexOfPipe = num2;
				}
				else if (Math.Abs(list[i].DistanceOfEnd - list[i - 1].DistanceOfEnd) < 0.032808398950131233)
				{
					list[i].IndexOfPipe = num2;
				}
				else
				{
					num2++;
					list[i].IndexOfPipe = num2;
				}
			}
			return list;
		}

		private List<RadiatorConnParam> OrderByRadiatorDouble(List<RadiatorConnParam> radiatorSet, ref XYZ basePnt)
		{
			List<RadiatorConnParam> list = new List<RadiatorConnParam>();
			this.ChangePipeLine(ref radiatorSet, 1, ref basePnt);
			this.ChangePipeLine(ref radiatorSet, 2, ref basePnt);
			if (this.SupplyPipe == null)
			{
				return list;
			}
			YJKPiping<Pipe> hypiping = new YJKPiping<Pipe>(this.SupplyPipe);
			XYZ origin = hypiping.StartConnector.Origin;
			XYZ origin2 = hypiping.EndConnector.Origin;
			XYZ xyz = origin.Subtract(origin2).Normalize();
			basePnt = ((origin.DistanceTo(basePnt) > origin2.DistanceTo(basePnt)) ? origin2 : origin);
			double num = 0.0001;
			foreach (RadiatorConnParam radiatorConnParam in radiatorSet)
			{
				double distanceOfEnd = radiatorConnParam.InExPipeConn.Origin.DistanceTo(basePnt);
				radiatorConnParam.DistanceOfEnd = distanceOfEnd;
				XYZ basisZ = radiatorConnParam.InConnector.CoordinateSystem.BasisZ;
				XYZ direction = xyz.CrossProduct(basisZ);
				double twoVectorAngle = YJKRevitTools.GetTwoVectorAngle(xyz, basisZ, direction);
				if (twoVectorAngle <= num || Math.Abs(twoVectorAngle - Math.PI) <= num || Math.Abs(twoVectorAngle - Math.PI*2) < num)
				{
					radiatorConnParam.ReDirection = 0;
				}
				else if (Math.Abs(twoVectorAngle - Math.PI*.5) <= num || Math.Abs(twoVectorAngle - 4.71238898038469) <= num)
				{
					radiatorConnParam.ReDirection = 1;
				}
				else
				{
					radiatorConnParam.ReDirection = 2;
				}
			}
			list = (from c in radiatorSet
			orderby c.DistanceOfEnd
			select c).ToList<RadiatorConnParam>();
			int num2 = 1;
			for (int i = 0; i < list.Count; i++)
			{
				if (i == 0)
				{
					list[i].IndexOfPipe = num2;
				}
				else if (Math.Abs(list[i].DistanceOfEnd - list[i - 1].DistanceOfEnd) < 0.032808398950131233)
				{
					list[i].IndexOfPipe = num2;
				}
				else
				{
					num2++;
					list[i].IndexOfPipe = num2;
				}
			}
			return list;
		}

		private bool ChangePipeLine(ref List<RadiatorConnParam> radiatorSet, int style, ref XYZ basePnt)
		{
			YJKPiping<Pipe> hypiping = null;
			if (style == 2 && this.ConnStyle == 1)
			{
				if (this.ReturnPipe != null)
				{
					hypiping = new YJKPiping<Pipe>(this.ReturnPipe);
				}
			}
			else if (this.SupplyPipe != null)
			{
				hypiping = new YJKPiping<Pipe>(this.SupplyPipe);
			}
			if (hypiping == null)
			{
				return false;
			}
			XYZ origin = hypiping.StartConnector.Origin;
			XYZ origin2 = hypiping.EndConnector.Origin;
			XYZ xyz = null;
			if (origin.DistanceTo(basePnt) < origin2.DistanceTo(basePnt))
			{
				basePnt = origin;
				xyz = origin2;
			}
			else
			{
				basePnt = origin2;
				xyz = origin;
			}
			YJKLine hyline = new YJKLine(origin, origin2);
			hyline.MakeUnBound();
			foreach (RadiatorConnParam radiatorConnParam in radiatorSet)
			{
				Connector connector = radiatorConnParam.InExPipeConn;
				if (style == 2)
				{
					connector = radiatorConnParam.OutExPipeConn;
				}
				if (connector != null)
				{
					XYZ origin3 = connector.Origin;
					XYZ project = hyline.GetProject(origin3);
					if (style == 1)
					{
						radiatorConnParam.PntOnPipeIn = project;
						radiatorConnParam.PntOnFaceIn = new XYZ(project.X, project.Y, origin3.Z);
					}
					if (style == 2)
					{
						radiatorConnParam.PntOnPipeOut = project;
						radiatorConnParam.PntOnFaceOut = new XYZ(project.X, project.Y, origin3.Z);
					}
					if (!hyline.IsPointOnLine(project))
					{
						double num = basePnt.DistanceTo(project);
						double num2 = xyz.DistanceTo(project);
						if (num > num2)
						{
							xyz = project;
						}
						else
						{
							basePnt = project;
						}
						hyline = new YJKLine(basePnt, xyz);
						hyline.MakeUnBound();
					}
				}
			}
			if (style == 2 && this.ConnStyle == 1)
			{
				this.returnPipe = hypiping.Extend(basePnt, xyz);
			}
			else
			{
				this.supplyPipe = hypiping.Extend(basePnt, xyz);
			}
			this.Doc.Regenerate();
			return true;
		}

		private List<RadiatorConnParam> InitialRadiatorParam(IList<FamilyInstance> radiators)
		{
			List<RadiatorConnParam> list = new List<RadiatorConnParam>();
			foreach (FamilyInstance familyInstance in radiators)
			{
				RadiatorConnParam radiatorConnParam = new RadiatorConnParam();
				radiatorConnParam.ElementId = familyInstance.Id.IntegerValue;
				radiatorConnParam.InExtend = UnitConvert.CovertToAPI(this.distanceSupply, (Autodesk.Revit.DB.DisplayUnitType)2);
				radiatorConnParam.OutExtend = UnitConvert.CovertToAPI(this.distanceReturn, (Autodesk.Revit.DB.DisplayUnitType)2);
				Connector inConnector = null;
				Connector outConnector = null;
				this.GetConnecctor(familyInstance, ref inConnector, ref outConnector);
				radiatorConnParam.InConnector = inConnector;
				radiatorConnParam.OutConnector = outConnector;
				radiatorConnParam.FacingOrientation = familyInstance.FacingOrientation;
				list.Add(radiatorConnParam);
			}
			return list;
		}

		private void JudgeConnPosition(int elemId, ref bool inBeUp, ref bool outBeUp)
		{
			ElementId elementId = new ElementId(elemId);
			Parameter parameter = this.doc.GetElementById(elementId).GetParameter("HYRadiatorType");
			if (parameter == null)
			{
				return;
			}
			string text = parameter.AsString();
			uint num = YArchitech.Revit.PrivateImplementationDetails.ComputeStringHash(text);
			if (num <= 2279835011u)
			{
				if (num <= 518729469u)
				{
					if (num != 401286136u)
					{
						if (num != 501951850u)
						{
							if (num != 518729469u)
							{
								goto IL_1C2;
							}
							if (!(text == "13"))
							{
								goto IL_1C2;
							}
						}
						else
						{
							if (!(text == "12"))
							{
								goto IL_1C2;
							}
							goto IL_1B4;
						}
					}
					else if (!(text == "14"))
					{
						goto IL_1C2;
					}
				}
				else if (num != 2247118416u)
				{
					if (num != 2263057392u)
					{
						if (num != 2279835011u)
						{
							goto IL_1C2;
						}
						if (!(text == "42"))
						{
							goto IL_1C2;
						}
						goto IL_1AD;
					}
					else
					{
						if (!(text == "43"))
						{
							goto IL_1C2;
						}
						goto IL_1BB;
					}
				}
				else
				{
					if (!(text == "32"))
					{
						goto IL_1C2;
					}
					goto IL_1AD;
				}
			}
			else if (num <= 2314375987u)
			{
				if (num != 2296612630u)
				{
					if (num != 2297451273u)
					{
						if (num != 2314375987u)
						{
							goto IL_1C2;
						}
						if (!(text == "24"))
						{
							goto IL_1C2;
						}
					}
					else
					{
						if (!(text == "31"))
						{
							goto IL_1C2;
						}
						goto IL_1AD;
					}
				}
				else
				{
					if (!(text == "41"))
					{
						goto IL_1C2;
					}
					goto IL_1AD;
				}
			}
			else if (num != 2347784130u)
			{
				if (num != 2364708844u)
				{
					if (num != 2398264082u)
					{
						goto IL_1C2;
					}
					if (!(text == "23"))
					{
						goto IL_1C2;
					}
				}
				else
				{
					if (!(text == "21"))
					{
						goto IL_1C2;
					}
					goto IL_1B4;
				}
			}
			else
			{
				if (!(text == "34"))
				{
					goto IL_1C2;
				}
				goto IL_1BB;
			}
			inBeUp = true;
			outBeUp = false;
			return;
			IL_1AD:
			inBeUp = false;
			outBeUp = true;
			return;
			IL_1B4:
			inBeUp = true;
			outBeUp = true;
			return;
			IL_1BB:
			inBeUp = false;
			outBeUp = false;
			return;
			IL_1C2:
			inBeUp = true;
			outBeUp = false;
		}

		private RadiatorConnParam InitialRadiatorParam(FamilyInstance radiator)
		{
			RadiatorConnParam radiatorConnParam = new RadiatorConnParam();
			radiatorConnParam.ElementId = radiator.Id.IntegerValue;
			radiatorConnParam.InExtend = UnitConvert.CovertToAPI(this.distanceSupply, (Autodesk.Revit.DB.DisplayUnitType)2);
			radiatorConnParam.OutExtend = UnitConvert.CovertToAPI(this.distanceReturn, (Autodesk.Revit.DB.DisplayUnitType)2);
			Connector inConnector = null;
			Connector outConnector = null;
			this.GetConnecctor(radiator, ref inConnector, ref outConnector);
			radiatorConnParam.InConnector = inConnector;
			radiatorConnParam.OutConnector = outConnector;
			radiatorConnParam.FacingOrientation = radiator.FacingOrientation;
			return radiatorConnParam;
		}

		private List<RadiatorConnParam> CreatLeadPipe(List<RadiatorConnParam> listConnParams)
		{
			List<RadiatorConnParam> list = new List<RadiatorConnParam>();
			foreach (RadiatorConnParam connParam in listConnParams)
			{
				RadiatorConnParam radiatorConnParam = this.CreatLeadPipe(connParam);
				if (radiatorConnParam != null)
				{
					list.Add(radiatorConnParam);
				}
			}
			return list;
		}

		private RadiatorConnParam CreatLeadPipe(RadiatorConnParam connParam)
		{
			Pipe pipe = null;
			Connector connector = null;
			if (this.SupplyPipe != null)
			{
				pipe = this.CreatRadiatorOutPipe(this.SupplyPipe, 1, connParam, ref connector);
				connParam.InPipe = pipe;
				connParam.InExPipeConn = connector;
			}
			if (this.ReturnPipe != null)
			{
				pipe = this.CreatRadiatorOutPipe(this.ReturnPipe, 2, connParam, ref connector);
				connParam.OutPipe = pipe;
				connParam.OutExPipeConn = connector;
			}
			if (this.ReturnPipe == null && this.SupplyPipe != null)
			{
				pipe = this.CreatRadiatorOutPipe(this.SupplyPipe, 2, connParam, ref connector);
				connParam.OutPipe = pipe;
				connParam.OutExPipeConn = connector;
			}
			if (pipe == null)
			{
				return null;
			}
			return connParam;
		}

		private Pipe CreatRadiatorOutPipe(Pipe basePipe, int connNum, RadiatorConnParam fcParam, ref Connector outConn)
		{
			Pipe pipe = null;
			XYZ xyz = null;
			List<FamilySymbol> list = new List<FamilySymbol>();
			if (connNum == 1 && fcParam.InConnector != null)
			{
				double diameter = fcParam.InConnector.Radius * 2.0;
				xyz = this.GetExtendPoint(fcParam.InConnector, fcParam.InExtend);
				pipe = YJKRevitTools.NewPipe(basePipe, fcParam.InConnector, xyz);
				this.SetDiameter(pipe, diameter);
				this.ConnPipeAndConnector(pipe, fcParam.InConnector);
				this.Doc.Regenerate();
				if (this.SymbolSupply != null)
				{
					list = new List<FamilySymbol>();
					list.Add(this.SymbolSupply);
					GroupValueManage groupValueManage = new GroupValueManage(this.Doc, pipe, fcParam.InConnector.Origin, 100.0, list);
					if (!groupValueManage.Go())
					{
						throw new Exception("阀件插入失败");
					}
					pipe = groupValueManage.GetEndPipe();
				}
			}
			else if (connNum == 2 && fcParam.OutConnector != null)
			{
				double diameter = fcParam.OutConnector.Radius * 2.0;
				xyz = this.GetExtendPoint(fcParam.OutConnector, fcParam.OutExtend);
				pipe = YJKRevitTools.NewPipe(basePipe, fcParam.OutConnector, xyz);
				this.SetDiameter(pipe, diameter);
				this.ConnPipeAndConnector(pipe, fcParam.OutConnector);
				this.Doc.Regenerate();
				if (this.SymbolReturn != null)
				{
					list = new List<FamilySymbol>();
					list.Add(this.SymbolReturn);
					GroupValueManage groupValueManage2 = new GroupValueManage(this.Doc, pipe, fcParam.OutConnector.Origin, 100.0, list);
					if (!groupValueManage2.Go())
					{
						throw new Exception("阀件插入失败");
					}
					pipe = groupValueManage2.GetEndPipe();
				}
			}
			this.doc.Regenerate();
			YJKPiping<Pipe> hypiping = new YJKPiping<Pipe>(pipe);
			double num = hypiping.StartConnector.Origin.DistanceTo(xyz);
			double num2 = hypiping.EndConnector.Origin.DistanceTo(xyz);
			outConn = ((num > num2) ? hypiping.EndConnector.Connector : hypiping.StartConnector.Connector);
			return pipe;
		}

		private XYZ GetExtendPoint(Connector conn, double extendLength)
		{
			XYZ origin = conn.Origin;
			XYZ basisZ = conn.CoordinateSystem.BasisZ;
			return origin.Add(basisZ * extendLength);
		}

		private bool ConnPipeAndConnector(Pipe pipe, Connector conn)
		{
			bool result = true;
			YJKPiping<Pipe> hypiping = new YJKPiping<Pipe>(pipe);
			double num = hypiping.StartConnector.Origin.DistanceTo(conn.Origin);
			double num2 = hypiping.EndConnector.Origin.DistanceTo(conn.Origin);
			((num > num2) ? hypiping.EndConnector.Connector : hypiping.StartConnector.Connector).ConnectTo(conn);
			return result;
		}

		private void SetDiameter(Pipe branchPipe, double diameter)
		{
			new YJKPiping<Pipe>(branchPipe).SetDiameter(diameter * 304.8);
		}

		private string ValidatingElements(List<Element> listElem)
		{
			string result = "";
			this.listRadiator = new List<FamilyInstance>();
			this.listPipe = new List<Pipe>();
			foreach (Element element in listElem)
			{
				int integerValue = element.Category.Id.IntegerValue;
				if (integerValue == -2008044)
				{
					this.listPipe.Add(element as Pipe);
				}
				if (integerValue == -2001140)
				{
					this.listRadiator.Add(element as FamilyInstance);
				}
			}
			if (this.listPipe.Count < 1)
			{
				if (this.ConnStyle == 1)
				{
					result = "选择的实体集合应该包含2根水管。";
				}
				else
				{
					result = "选择的实体集合应该包含1根水管。";
				}
			}
			else if (this.listPipe.Count == 1 && this.ConnStyle == 1)
			{
				result = "选择的实体集合应该包含2根水管。";
			}
			if (this.listRadiator.Count < 1)
			{
				result = "选择的实体集合应该包含1个散热器。";
			}
			return result;
		}

		public IList<FamilyInstance> ListRadiator
		{
			get
			{
				return this.listRadiator;
			}
			set
			{
				this.listRadiator = value;
			}
		}

		public IList<Pipe> ListPipe
		{
			get
			{
				return this.listPipe;
			}
			set
			{
				this.listPipe = value;
			}
		}

		public Pipe SupplyPipe
		{
			get
			{
				return this.supplyPipe;
			}
			set
			{
				this.supplyPipe = value;
			}
		}

		public Pipe ReturnPipe
		{
			get
			{
				return this.returnPipe;
			}
			set
			{
				this.returnPipe = value;
			}
		}

		public Document Doc
		{
			get
			{
				return this.doc;
			}
			set
			{
				this.doc = value;
			}
		}

		public Selection Sel
		{
			get
			{
				return this.sel;
			}
			set
			{
				this.sel = value;
			}
		}

		public FamilySymbol SymbolSupply
		{
			get
			{
				return this.symbolSupply;
			}
			set
			{
				this.symbolSupply = value;
			}
		}

		public FamilySymbol SymbolReturn
		{
			get
			{
				return this.symbolReturn;
			}
			set
			{
				this.symbolReturn = value;
			}
		}

		public double DistanceSupply
		{
			get
			{
				return this.distanceSupply;
			}
			set
			{
				this.distanceSupply = value;
			}
		}

		public double DistanceReturn
		{
			get
			{
				return this.distanceReturn;
			}
			set
			{
				this.distanceReturn = value;
			}
		}

		public int ConnStyle
		{
			get
			{
				return this.connStyle;
			}
			set
			{
				this.connStyle = value;
			}
		}

		public string Message
		{
			get
			{
				return this.message;
			}
			set
			{
				this.message = value;
			}
		}

		private readonly double m_precision = 0.0001;

		private static double coeff = 3.0;

		private List<Pipe> riserPipe = new List<Pipe>();

		private IList<FamilyInstance> listRadiator;

		private IList<Pipe> listPipe;

		private Pipe supplyPipe;

		private Pipe returnPipe;

		private Document doc;

		private Selection sel;

		private FamilySymbol symbolSupply;

		private FamilySymbol symbolReturn;

		private double distanceSupply;

		private double distanceReturn;

		private int connStyle;

		private string message;

		private enum DoubleConnPipesType
		{
			RPipeNormal,
			RPipeOverIn1,
			RPipeOverIn2,
			RPipeOverOut1,
			RPipeOverOut2,
			RPipeDoubleElbowIn,
			RPipeDoubleElbowOut,
			RPipeSingleElbowIn,
			RPipeSingleElbowOut,
			HPipeNormal,
			HPipeOverIn1,
			HPipeOverIn2,
			HPipeOverOut1,
			HPipeOverOut2,
			HPipeDoubleElbowIn,
			HPipeDoubleElbowOut,
			HPipeDoubleElbow,
			HPipeDoubleElbowInAndOverOut,
			HPipeDoubleElbowOutAndOverIn,
			HPipeSingleElbowIn,
			HPipeSingleElbowOut,
			HPipeSingleElbowInAndOverOut,
			HPipeSingleElbowOutAndOverIn,
			HPipeSingleElbow,
			HPipeOverInlead,
			HPipeOverOutlead,
			Invalid
		}
	}
}
